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

asked on

Error in php select pdo

<?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
ASKER CERTIFIED SOLUTION
Avatar of Mukesh Yadav
Mukesh Yadav
Flag of India 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
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.
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
Avatar of sanchit gupta
sanchit gupta

ASKER

i also want to make a link to the url both from title and url itself
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?
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
stale question