cpharry Posted December 31, 2008 Share Posted December 31, 2008 Hi, Whenever I run my script that if being used in development to make a forum I get this message. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\myprogram\xampp\htdocs\xampp\testcategories.php on line 18 What can I do to stop it ? Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/ Share on other sites More sharing options...
DeanWhitehouse Posted December 31, 2008 Share Posted December 31, 2008 Your sql query is wrong, post it here or we can't help. Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726889 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 $sql="SELECT * FROM forum WHERE ParentID='1'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result)){ echo "<td width=\"53%\" align=\"center\" bgcolor=\"#E6E6E6\"> <div align=\"left\"> <a href=\"view_forums.php?id=" . $row['ID'] . "\">" . $row['Name'] . "</a> </div> </td>\n"; } mysql_close(); Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726891 Share on other sites More sharing options...
DeanWhitehouse Posted December 31, 2008 Share Posted December 31, 2008 $result=mysql_query($sql); to $result=mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726892 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 Nope, sorry I still get the same error on the same line. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\myprogram\xampp\htdocs\xampp\testcategories.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726895 Share on other sites More sharing options...
DeanWhitehouse Posted December 31, 2008 Share Posted December 31, 2008 If you change what i said, and you are showing all the code then you won't. It would show another error and stop the rest of the page running. Show your current code. Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726897 Share on other sites More sharing options...
revraz Posted December 31, 2008 Share Posted December 31, 2008 Try to remove the single quotes from ParentID='1' Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726898 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 <html> <body> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <?php $host="localhost"; // Host name $username="user"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="forum"; // Table name // Connect to server and select databse. mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select DB"); $sql="SELECT * FROM forum WHERE ParentID=1"; $result=mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<td width=\"53%\" align=\"center\" bgcolor=\"#E6E6E6\"> <div align=\"left\"> <a href=\"view_forums.php?id=" . $row['ID'] . "\">" . $row['Name'] . "</a> </div> </td>\n"; } mysql_close(); ?> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726900 Share on other sites More sharing options...
DeanWhitehouse Posted December 31, 2008 Share Posted December 31, 2008 try $sql = "SELECT * FROM `forum` WHERE `ParentID` = '1'"; Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726912 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 Same error, same place. Any ideas. Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726914 Share on other sites More sharing options...
revraz Posted December 31, 2008 Share Posted December 31, 2008 With the mysql_error in there, it should die on the query and output an error. You sure you are running this script and not another one? Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726915 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 Yes thats what it comes back with. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\myprogram\xampp\htdocs\xampp\testcategories.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726921 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2008 Share Posted December 31, 2008 I put the code you posted into my editor. Line 18 is blank, so the code you post is not the code you're running. Please clear your browser's cache and try again. Ken Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726926 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 Done and natta, I will upload it to the web server and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726931 Share on other sites More sharing options...
revraz Posted December 31, 2008 Share Posted December 31, 2008 If you didnt put it on the webserver, how are you testing the changes? Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726957 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2008 Share Posted December 31, 2008 The OP is using a xampp installation on the PC. Ken Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726967 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 I had xampp on my of. Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-726994 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 Ok, I got everything working except for I need it to list the categories for example. Categories - Bold Then the forums related to that under, not sure how to though. The present code dont allow that. If I have them in the database the way that I want them, I mean the order of them. How do I get it so that the categories with a ParentID of 0 to be bold and the other to be normal. Any suggestions ? Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-727067 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 Here is the updated code. <?php $host="localhost"; // Host name $username="simnetwo"; // Mysql username $password="Sorry, cant put it in."; // Mysql password $db_name="simnetwo_test"; // Database name $tbl_name="forum"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql= "SElECT * FROM `forum` WHERE ParentID='1'"; $result=mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ ?> <body> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="53%" align="center" bgcolor="#E6E6E6"><div align="left"><a href="view_forum.php?id=<? echo $row['ID']; ?>"><? echo $row['Name']; ?></a></div></td> <td width="15%" align="center" bgcolor="#E6E6E6"> </td> <td width="13%" align="center" bgcolor="#E6E6E6"> </td> <td width="13%" align="center" bgcolor="#E6E6E6"> </td> </tr> <tr> <td bgcolor="#FFFFFF"><BR></td> <td align="center" bgcolor="#FFFFFF"> </td> <td align="center" bgcolor="#FFFFFF"> </td> <td align="center" bgcolor="#FFFFFF"> </td> </tr> <?php } mysql_close(); ?> <tr> <td align="right" bgcolor="#E6E6E6"> </td> <td align="right" bgcolor="#E6E6E6"> </td> <td align="right" bgcolor="#E6E6E6"> </td> <td align="right" bgcolor="#E6E6E6"> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-727111 Share on other sites More sharing options...
cpharry Posted December 31, 2008 Author Share Posted December 31, 2008 I have uploaded the new files to the net and it all works, displaying all the forums with the ParentID of 1. What I want to do now is the following.. ---------------------- } CATEGORY NAME } Would obviously like this to ---------------------- } be looped so that it continues. RELEVANT FORUM } Is this possible ? The layout of the table would be how it would come out on the page; what I thought was that I could have a field where it has either a 0 or 1. 0 = Category 1 = Forum Just how do I do that code wise. Quote Link to comment https://forums.phpfreaks.com/topic/138990-solved-help-with-the-error/#findComment-727275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.