Mr Blue Mr Blue - 7 months ago 18
SQL Question

How to echo row from custom statement another than $stmt

My code :

$stmt = $user_home->runQuery("SELECT * FROM tbl_users, tbl_products WHERE userID=:uid and creatorID=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$scheck = $user_home->runQuery("SELECT * FROM tbl_products WHERE serialNumber=:snr");
$scheck->execute(array(":snr"=>$snumber));


How to echo row from $scheck?

When I type
$row['artNumber']
it's showing row from $stmt.

I try to do
$scheck['artNumber']
but it does not show anything.

I tried to find answer in google, but I did not find the solution.

Answer

When you are already using fetch on another statement above, why cant you use it here too?

$scheckrow = $scheck->fetch(PDO::FETCH_ASSOC);

Then you can simply do what you're already doing

echo $scheckrow['artNumber'];