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
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...

Link to comment
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");

$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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  ???

Link to comment
Share on other sites

require_once("config.php");

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

mysql_select_db($db, $connection) OR DIE("Selection Error:" . mysql_error() . "<br /> For Database: $db");

 

See what that gets ya.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.