Home single instead of double select statement
Reply: 0

single instead of double select statement

user791
1#
user791 Published in April 20, 2018, 6:00 pm

first table - bplus - has a column named home01 with values identical to some values in column fname of table banners

$items = '';
$sql = "select home01 from bplus";
$st = $db->query($sql);
$arr = $st->fetchAll(PDO::FETCH_COLUMN);
foreach ($arr as $el){
    $el = trim($el);
    $sqlb = "select * from banners where fname = '" . $el . "'";
    $stb = $db->query($sqlb);
    $row = $stb->fetch();
    $items .= "<img class='itemtop' src = '../banners/" . $el . "' alt='img' data-id = " . $row['id'] . " data-fname = '" . $row['fname'] . ">\n"; 
}
echo $items;

this works but probably there is a shorter way, with a single select statement.

Any help?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299764 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO