perezf Posted April 21, 2007 Share Posted April 21, 2007 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 More sharing options...
fanfavorite Posted April 21, 2007 Share Posted April 21, 2007 Everything seems right from the code, so I would check this line: SELECT * FROM links order by name Make sure "links" is your table name. Remember that it is case sensitive. Link to comment https://forums.phpfreaks.com/topic/48022-php-error-help/#findComment-234723 Share on other sites More sharing options...
perezf Posted April 21, 2007 Author Share Posted April 21, 2007 that was the problem thanks for the reminder Link to comment https://forums.phpfreaks.com/topic/48022-php-error-help/#findComment-234726 Share on other sites More sharing options...
kenrbnsn Posted April 21, 2007 Share Posted April 21, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.