Link to home
Start Free TrialLog in
Avatar of sanchit gupta
sanchit gupta

asked on

Errors in links opening

I have made a code which selects url and title from links table in database. I want links to the respective urls. For eg: if url on the page says "www.google.com" upon clicking on it it should redirect to google.com. The below code displays an error of headers already sent.

<?php
 include ("./inc/header.inc.php");
$userid="";
$dblinks = DB::query('SELECT url, title FROM links WHERE user_id!=:userid ORDER BY id DESC', array(':userid'=>$userid));
$links = "";
$links_t = "";
foreach ($dblinks as $u) {
    $links .= $u['url'].'<br>'.$u['title'].'<hr>' ;
}
?>
<div class="links">
    <?php
header('Location: echo $links;'); ?>
 </div>

Open in new window

Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

The quick fix:
Add ob_start() after line 1:

<?php
ob_start();
 include ("./inc/header.inc.php");

Open in new window

SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sanchit gupta
sanchit gupta

ASKER

That removed that error but still desired output is not achieved
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@gr8gonzo it worked thanks!

Could you please help me with styling too. As in I want  to style both url and title differently.
@gr8gonzo Could you please help me with styling too. As in I want to style both URL and title differently.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just want to modify font size for both.
Okay. CSS is the correct way to do that.
how to apply css in this case when you have same class for both variables?
If you need to distinguish between two HTML elements, there are several ways to do that, but the simplest way is probably to wrap the title in a <span> tag with a named class attribute.