Jump to content

[SOLVED] [Help] Warning: mysql_num_rows()


Mutley

Recommended Posts

Error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 9

 

Code:

<table align="left" width="80%">

<?php
require_once("connection.php");

$query = "SELECT id, name, surname FROM profiles ORDER BY surname, name";
$result = mysql_query($query);

if(mysql_num_rows($result)!=0) {

while(list($id, $name, $surname) = mysql_fetch_row($result)) {
?>
  <tr>
    <td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td>
  </tr>
<?php
   }
}

else {

echo "No profiles were found";
}


?>
</table>

 

Anyone know what the problem is?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/
Share on other sites

<table align="left" width="80%">

<?php

require_once("connection.php");

$query = mysql_query("SELECT id, name, surname FROM profiles ORDER BY surname, name");

 

if(mysql_num_rows($query)>0) {

while(list($id, $name, $surname) = mysql_fetch_row($query)) {

?>

<tr><td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td></tr>

<?php

}

}else{echo "No profiles were found";}

?>

</table>

 

 

Try the above...

<table align="left" width="80%">

<?php

require_once("connection.php");

$query = mysql_query("SELECT id, name, surname FROM profiles ORDER BY surname, name");

$numrows = mysql_num_rows($query);

if ($numrows>0){

while(list($id, $name, $surname) = mysql_fetch_row($query)) {

?>

<tr><td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td></tr>

<?php

}

}else{echo "No profiles were found";}

?>

</table>

This isnt tested... This is how i would code it..

<table align="left" width="80%">
<?php
require_once("connection.php");
$query = mysql_query("SELECT `id` , `name` , `surname` FROM `profiles` ORDER BY surname, name DESC");
$queryRows = mysql_num_rows($query);

if ($queryRows > 0){
while ($queryFetch = mysql_fetch_row($query)){
echo("<tr><td align='left'><a href='profiles.php?id=$queryFetch[0]'>$queryFetch[2], $queryFetch[1]</a></td></tr>");
}
}else{
echo("<tr><td align='center'>No Profiles Found!</td></tr>");
}
?>
</table>

 

:D

Are you sure your MySQL is returning anything at all and not just throwing errors? Hmmmm =)

 

table align="left" width="80%">
<?php
require_once("connection.php");

$query = "SELECT id, name, surname FROM profiles ORDER BY surname, name";
$result = mysql_query($query) OR DIE("SQL ERROR FOR QUERY:" . $query . "<br />ERROR: " . mysql_error());

if(mysql_num_rows($result)!=0) {

while(list($id, $name, $surname) = mysql_fetch_row($result)) {
?>
  <tr>
    <td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td>
  </tr>
<?php
   }
}

else {

echo "No profiles were found";
}


?>
</table>

 

Post the error results.

It says:

SQL ERROR FOR QUERY:SELECT id, name, surname FROM profiles ORDER BY surname, name

ERROR: No database selected

 

My connection.php:

 

require_once("config.php");

$connection = mysql_connect($host, $user, $pwd) or die("&error1=".mysql_error());

mysql_select_db($db, $connection);

 

My config.php:

 

$host = "localhost";
$user = "yorkrufc_rufc";
$pwd = "";//removed
$db = "yorkrufc_rufc";

 

So it should connect.  ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.