Jump to content

PHP Error Help


perezf

Recommended Posts

I have one error that loads all the time and i cant figure out why it happens

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in \\nas34ent\domains\j\jackpotavenue.com\user\htdocs\affiliates1.php on line 34

 

Here is the code below if some one can please help me


<?php
$name = $_POST['name'];
$url = $_POST['url'];
$desc = $_POST['desc'];

$host = "localhost";
$username = "******";
$password = "******";
$db = "jackpotavenue";

$connection = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database');
mysql_select_db ($db, $connection) or die ('Unable to select database');

$query = "SELECT * FROM links order by name";
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();

$i = 0;
while ($i < $num) {
$name = mysql_result ($result, $i, "name");
$url = mysql_result ($result, $i, "url");
$desc = mysql_result ($result, $i, "desc");

echo "<a href=\"$url\">$name</a> - $desc <br />";

$i++;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/48022-php-error-help/
Share on other sites

A better (IMHO) way to do this would be to use the mysql_fetch_assoc() function:

<?php
$query = "SELECT * FROM links order by name";
$result = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error());
$num = mysql_num_rows($result);
if ($num > 0)
   while ($rw = mysql_fetch_assoc($result)) 	
echo '<a href="' . $rw['url'] .'">' . $rw['name'] . '</a> - ' . $rw['desc']  . '<br />';
?>

 

Shorter code, easier to understand what's being used.

 

Ken

 

Link to comment
https://forums.phpfreaks.com/topic/48022-php-error-help/#findComment-234762
Share on other sites

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.