We help IT Professionals succeed at work.

Error in php select pdo

sanchit gupta
on
106 Views
Last Modified: 2017-04-03
<?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'];
    //$links .= $
}
    foreach ($dblinks as $t) {
            $links_t .= $t['title']."<hr /></br />";

}
?>

<div class="links">
<?php echo $links;
echo $links_t;
?>
 </div>

Open in new window


The output is coming as all the urls one by one and the title one by one. I want url and title to be together then a <hr> then next url and title and so on. any help
Comment
Watch Question

Full Stack Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
You do not need to have two foreach loops for this already $dblinks will have both

foreach ($dblinks as $u) {
    $links .= $u['url'].''.$u['title'].'<hr>' ;
    //$links .= $
}

Open in new window


If you can what is the html output you are trying to achieve, it will be better to understand and construct that.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Some good "getting started" examples for PHP and MySQL when using PDO are available in this article
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

Author

Commented:
i also want to make a link to the url both from title and url itself
CERTIFIED EXPERT

Commented:
i also want to make a link to the url both from title and url itself

Can you post a sample output you are looking for?
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
@PeosJohn this particular thing
Most Valuable Expert 2011
Author of the Year 2014

Commented:
stale question