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
PHPWeb Development

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Mukesh Yadav

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Peos John

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.
Ray Paseur

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
sanchit gupta

ASKER
i also want to make a link to the url both from title and url itself
Your help has saved me hundreds of hours of internet surfing.
fblack61
Peos John

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
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sanchit gupta

ASKER
@PeosJohn this particular thing
Ray Paseur

stale question
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.