jonatec 0 Newbie Poster

Hi

Please take a look at my code snippet. Works fine, however I don't know how to get the number of rows returned so that I can handle it accordingly. Any ideas please?

<?php
require ('mysqli_connect.php'); // Connect to the Db.

$sql = "CALL customers_for_rep(?, ?)";

$stmt = $dbc->prepare($sql);

if ($dbc->errno) {die($dbc->errno.":: ".$dbc->error);}

$stmt->bind_param("is", $i_user_id, $i_firstName);

$i_user_id = 2;
$i_firstName = "David";

$stmt->execute( );

$rows = $stmt->num_rows;

if ($dbc->errno) {die($dbc->errno.": ".$dbc->error);}

$stmt->bind_result($first_name, $last_name);

echo "Rows returned: " . $rows . "</p>";

$buf = "";
$buf .= '<table align="center" cellspacing="3" cellpadding="3" width="70%" border="1">';
$buf .= '  <tr>';
$buf .= '    <td class="td01">First Name</td>';
$buf .= '    <td class="td01">Last Name</td>';
$buf .= '  </tr>';
while ($stmt->fetch( )) {
	$buf .= '<tr>';
	$buf .= '  <td>' . $first_name . '</td>';
	$buf .= '  <td>' . $last_name . '</td>';
	$buf .= '</tr>';	
}
$buf .= '</table>';
echo $buf;
echo "<p/>made it.";
mysqli_close($dbc);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.