| PHP MySql Error
|
ddregallo

msg:3256459 | 1:30 am on Feb 19, 2007 (gmt 0) | When the code below runs it gives me the following error. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in root/public_html/articleindex.php on line 24 I don't know why. Can anyone help? The second occurance of mysql_fetch_array() is where the problem is. <?php $acats_handle = mysql_connect($sql_host, $sql_username, $sql_password); mysql_select_db($db, $acats_handle);$acats_query = "SELECT record_number, Name, Description FROM Article_Categories;"; $acats_result = mysql_query($acats_query, $acats_handle); print("<table>"); print("<tr class=\"cattable_head\"><td colspan=\"2\">Articles Table of Contents</td></tr>"); while($i = mysql_fetch_array($acats_result)) { // For each category print("<tr>");// List this category print("<td> <a href=\"?catid=$i[record_number]\">$i[Name]</a> </td>"); print("<td> <p>$i[Description]</p> </td>"); print("</tr>"); print("<tr>"); // List articles under this category print("<td></td>"); // Bump to column 2 print("<table>"); $articles_result = mysql_query($articles_query, $acats_handle); $articles_query = "SELECT record_number, title, synopsis FROM SC_Articles WHERE category_record_number=$i[record_number] AND visible=1;"; while($x = mysql_fetch_array($articles_result)) { // For each article in current category print("<tr>"); print("<td> <a href=\"?article=$x[record_number]\">$x[title]</a> </td>"); print("<td> <p>$x[synopsis]</p> </td>"); print("</tr>"); } } print("</table>"); ?>
|
phpmaven

msg:3256477 | 2:22 am on Feb 19, 2007 (gmt 0) | You need to swap these two lines: $articles_result = mysql_query($articles_query, $acats_handle); $articles_query = "SELECT record_number, title, synopsis FROM SC_Articles WHERE category_record_number=$i[record_number] AND visible=1;"; You are trying to run the query before you define the value of $articles_query
|
camilord

msg:3256662 | 9:03 am on Feb 19, 2007 (gmt 0) | $acats_handle = mysql_connect($sql_host, $sql_username, $sql_password); mysql_select_db($db, $acats_handle); $acats_query = "SELECT record_number, Name, Description FROM Article_Categories;"; $acats_result = mysql_query($acats_query); $acats_limit = mysql_num_rows($acats_result); if ($acats_limit > 0) { for ($i = 0; $i < $acats_limit; $i++) { $cid = mysql_result($acats_result,$i,'record_number'); //continue the statements here... } }
|
|
|