Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of row wrong

Status
Not open for further replies.

TTA23

MIS
Sep 26, 2006
41
US
I have a select query and I am using the == mysql_num_rows($result) that give a value that is always the number of row I see + 1.

How can I correct this?
thanks
 
i don't understand your question. can you re-ask and provide some code to exemplify the behaviour you are concerned about?
 
For ex. I have a table with 120 name. I have a query that retrieve all the names(120).
I have a While ... statement that shows the name in the browser.

Each time if I use the statement mysql_num_rows($result), it will show that I have 120 names, but I only print 119 in the browser.
Cannot figure why I always miss one name.
 
ok. try this

Code:
$tablename = '';  //fill in the table name

$sql = "SELECT *, SQL_CALC_FOUND_ROWS from $tablename";
$result = mysql_query($sql) or die(mysql_error());
$php_num_rows = mysql_num_rows($result);

//iterate the rows
$counter = 0;
echo "<table border=\"1\">"
while ($row=mysql_fetch_assoc($result)){
 $counter++;
 echo "<tr>";
 foreach($row as $col){
  echo "<td>$col</td>"; 
 }
 echo "</tr>";
}
echo "</table>";
//retrieve SQL calculation
$result = mysql_query("select found_rows");
$sqlNumRows = myqsl_result($result ,0,0);
echo <<<HTML
PHP coded solution reports $php_num_rows rows<br/>
Number of outputted rows were $counter <br/>
Mysql reports that it found $sqlNumRows rows 
HTML;
 
Oh!
Thanks for the full sample - i will try this shortly.
This PHP is new to me since i only use ASP. Therefore some obvious things are not always obvious.
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top