am having problem with $stmt->store_result & $stmt->fetch

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

am having problem with $stmt->store_result & $stmt->fetch

Post by adsegzy »

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.

Code: Select all

//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'];
}

Code: Select all

//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
Post Reply