PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Jul 07, 2020 1:03 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat May 21, 2016 5:20 pm 
Offline
Forum Contributor

Joined: Tue Jul 28, 2009 9:26 am
Posts: 184
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 42 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group