We help IT Professionals succeed at work.

New podcast episode! Our very own Community Manager, Rob Jurd, gives his insight on the value of an online community. Listen Now!

x

Errors in links opening

sanchit gupta
on
56 Views
Last Modified: 2017-11-26
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

Comment
Watch Question

gr8gonzoConsultant
CERTIFIED EXPERT

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

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

Open in new window

gr8gonzoConsultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
That removed that error but still desired output is not achieved
Consultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
@gr8gonzo it worked thanks!

Could you please help me with styling too. As in I want  to style both url and title differently.

Author

Commented:
@gr8gonzo Could you please help me with styling too. As in I want to style both URL and title differently.
gr8gonzoConsultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I just want to modify font size for both.
gr8gonzoConsultant
CERTIFIED EXPERT

Commented:
Okay. CSS is the correct way to do that.

Author

Commented:
how to apply css in this case when you have same class for both variables?
gr8gonzoConsultant
CERTIFIED EXPERT

Commented:
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.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.