How to check if there are any results during ($ row = mysql_fetch_array in PHP

I am trying to figure out how to handle this, the results are not coming back, how would I do this?

while ($ row = mysql_fetch_array ($ Result))

So if there are results: print them

else: show link

+5
source share
6 answers

http://ca3.php.net/manual/en/function.mysql-num-rows.php

if(mysql_num_rows($result) > 0) {
   while($row = mysql_fetch_array($result)) { ... }
} else {
  // show link
}
+13
source

You can use mysql_num_rows()to find out how many results are found. Using this with a simple one if-statement, and you can determine what action to take.

if (mysql_num_rows($result) > 0) {
  // do while loop
} else {
  // show link
}
+6
source

mysql_num_rows(), , , . mysql_unbuffered_query(), .

:

$found_row = false;

while ($row = mysql_fetch_array($result)) {
  $found_row = true;
  . . .
}

if ($found_row == false) {
  // show link
}

$found_row true, . , SQL-.

+2

mysql_num_rows :

if($result) {
   // return db results
} else {
   // no result
}
+1

:

if (!($row = mysql_fetch_array($descResult)))
     {
     echo "<tr><td>Add Link</td></tr>";
}
0

mysql_num_rows() ()

if ( false===($row=mysql_fetch_array($result, MYSQL_ASSOC)) ) {
  echo 'no rows in result set';
}
else {
  do {
    echo $row['X'];
  } while ( false===($row=mysql_fetch_array($result, MYSQL_ASSOC)) );
}

fetch ( if-statement while-clause).

0

All Articles