PHP Developers Network
http://forums.devnetwork.net/

am having problem with $stmt->store_result & $stmt->fetch
http://forums.devnetwork.net/viewtopic.php?f=1&t=142588
Page 1 of 1

Author:  adsegzy [ Sat May 21, 2016 5:20 pm ]
Post subject:  am having problem with $stmt->store_result & $stmt->fetch

Hello,
I am using OO prepared statement. I need to count the number of rows returned and echo out the rows. But the problem is that i can only echo $stmt->num_row only if I include $stmt->store_result(). But if I include $stmt->store_result(), i can't echo out the rows. Below is my script.

Syntax: [ Download ] [ Hide ]
//THIS WILL ECHO THE num_rows BUT WILL NOT ECHO THE DATA FROM THE DB TABLE

$get_user = $conn->prepare("SELECT * FROM realtors_admins WHERE realtor=? ORDER BY unik DESC");
$get_user->bind_param('s', $remail);
$get_user->execute();
$get_user->store_result();
$result = $get_user->get_result();

echo $get_user->num_rows.".";

while ($row = $result->fetch_assoc()) {
echo .$row['fname']." ".$row['lname'];
}
 


Syntax: [ Download ] [ Hide ]
//THIS WILL NOT ECHO num_rows BUT WILL ECHO THE DATA FROM THE DB TABLE
$get_user = $dWay->prepare("SELECT * FROM realtors_admins WHERE realtor=? ORDER BY unik DESC");
$get_user->bind_param('s', $remail);
$get_user->execute();

$result = $get_user->get_result();

echo $get_user->num_rows.".";

while ($row = $result->fetch_assoc()) {
echo .$row['fname']." ".$row['lname'];
}
 


Also when can one use $stmt->fetch() and $stmt->fetch_assoc() ?

Thanks

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/