lmcgr44 Posted February 10, 2011 Share Posted February 10, 2011 hello i keep getting the Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/cookbook/public_html/forum/index.php on line 26 for my code <?php session_start(); include_once "../scripts/connect_to_mysql.php"; // Connect to the database $sql = mysql_query("SELECT * FROM forum_sections ORDER BY ordered ASC LIMIT 10"); $displayList = ""; // Initialize the display variable here while($row = mysql_fetch_array($sql)){ $sectionID = $row["id"]; $sectionTitle = $row["title"]; $displayList .= '<br /><a href="section.php?id=' . $sectionID . '"><img src="style/sectionPic.jpg" width="61" height="23" alt="Section" /> ' . $sectionTitle . '</a><br /><hr />'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="style/style.css" rel="stylesheet" type="text/css" /> <title>Web Intersect Forum</title> </head> <body> <?php include_once("template_header.php"); ?> <table style="background-color: #F0F0F0; border:#069 1px solid; border-top:none;" width="900" border="0" align="center" cellpadding="12" cellspacing="0"> <tr> <td width="731" valign="top"> <div id="breadcrumbs"><a href="http://www.webintersect.com">Web Intersect Home</a></div> <div id="sectionLinks"><ul><?php echo $displayList; ?></ul></div></td> <td width="189" valign="top"><div style=" width:160px; height:600px; background-color: #999; color: #CCC; padding:12px;"> <br /><br /><br /> <h3>Ad Space or Whatever</h3> </div></td> </tr> </table> <?php include_once("template_footer.php"); ?> </body> </html> can anyone please tell me why i get this? Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/ Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 update: $query = "SELECT * FROM forum_sections ORDER BY ordered ASC LIMIT 10"; $sql = mysql_query($query) or die(mysql_error() . " IN $query"); Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172302 Share on other sites More sharing options...
lmcgr44 Posted February 10, 2011 Author Share Posted February 10, 2011 update: $query = "SELECT * FROM forum_sections ORDER BY ordered ASC LIMIT 10"; $sql = mysql_query($query) or die(mysql_error() . " IN $query"); hello can u please tell me where to update this? Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172304 Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 replace this: $sql = mysql_query("SELECT * FROM forum_sections ORDER BY ordered ASC LIMIT 10"); Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172305 Share on other sites More sharing options...
lmcgr44 Posted February 10, 2011 Author Share Posted February 10, 2011 replace this: $sql = mysql_query("SELECT * FROM forum_sections ORDER BY ordered ASC LIMIT 10"); hello thanks, but now it just comes up with Unknown column 'ordered' in 'order clause' IN SELECT * FROM forum_sections ORDER BY ordered ASC LIMIT 10 Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172306 Share on other sites More sharing options...
Muddy_Funster Posted February 10, 2011 Share Posted February 10, 2011 then you don't have a field named ordered in your database Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172307 Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 correct. the query was failing, therefore the code after it was failing. the SQL is invalid, as there is no column named 'ordered' Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172308 Share on other sites More sharing options...
lmcgr44 Posted February 10, 2011 Author Share Posted February 10, 2011 then you don't have a field named ordered in your database thank-you, i just realised i made a spelling mistake in the database with ordered thanks for your help guys Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172309 Share on other sites More sharing options...
lmcgr44 Posted February 10, 2011 Author Share Posted February 10, 2011 correct. the query was failing, therefore the code after it was failing. the SQL is invalid, as there is no column named 'ordered' hey sorry but one more thing i get another warning on another page saying Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/cookbook/public_html/forum/section.php on line 26 for the code <?php session_start(); include_once ("../wi_class_files/agoTimeFormat.php"); $myAgoObject = new convertToAgo; include_once "../scripts/connect_to_mysql.php"; // Connect to the database // Get the section ID from the url variable coming in if (isset($_GET['id']) && $_GET['id'] != "") { $sid = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter all characters except numbers for security } else { echo "ERROR: Variables to run this script have been removed from the URL."; exit(); } // Query the database for that section id, make sure it exists and get the section title $sql = mysql_query("SELECT * FROM forum_sections WHERE id='$sid' LIMIT 1"); $numRows = mysql_num_rows($sql); if ($numRows < 1) { echo "ERROR: That section deos not exist you have tampered with our URLs."; exit(); } while($row = mysql_fetch_array($sql)){ $sectionTitle = $row["title"]; } // Use the section ID to query the "forum_posts" table in the database to get all the threads for this section $sql = mysql_query("SELECT * FROM forum_posts WHERE type='a' AND section_id='$sid' ORDER BY date_time DESC LIMIT 25"); $dynamicList = ""; $numRows = mysql_num_rows($sql); if ($numRows < 1) { $dynamicList = "There are no threads in this section yet. You can be the first to post."; } else { while($row = mysql_fetch_array($sql)){ $thread_id = $row["id"]; $post_author = $row["post_author"]; $post_author_id = $row["post_author_id"]; $date_time = $row["date_time"]; $convertedTime = ($myAgoObject -> convert_datetime($date_time)); $whenPost = ($myAgoObject -> makeAgo($convertedTime)); $thread_title = $row["thread_title"]; $dynamicList .= '<img src="style/threadPic.jpg" width="26" height="18" alt="Topic" /> ' . $post_author . ' - <a href="view_thread.php?id=' . $thread_id . '">' . $thread_title . '</a> - ' . $whenPost . '<br />'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="style/style.css" rel="stylesheet" type="text/css" /> <title><?php echo $sectionTitle; ?> Forum</title> </head> <body> <?php include_once("template_header.php"); ?> <table style="background-color: #F0F0F0; border:#069 1px solid; border-top:none;" width="900" border="0" align="center" cellpadding="12" cellspacing="0"> <tr> <td width="731" valign="top"> <div id="breadcrumbs"><a href="http://www.webintersect.com">Web Intersect Home</a> ← <a href="http://www.webintersect.com/forum">Forum Home</a></div> <h1 style="margin-left:12px;"><?php echo $sectionTitle; ?> Forum</h1> <form action="new_topic.php" method="post"> <input name="forum_id" type="hidden" value="<?php echo $sid; ?>" /> <input name="forum_title" type="hidden" value="<?php echo $sectionTitle; ?>" /> <input name="myBtn1" type="submit" value="Create New Topic" style="font-size:16px; padding:12px;" /> </form> <br /><br /> <div style="margin-left:12px; font-size:14px; line-height:1.5em;"><?php echo $dynamicList; ?></div> <br /><br /><br /></td> <td width="189" valign="top"><div style=" width:160px; height:600px; background-color: #999; color: #CCC; padding:12px;"> <br /> <br /> <br /> <h3>Ad Space or Whatever</h3> </div></td> </tr> </table> <?php include_once("template_footer.php"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172313 Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 error on line 26 due to failure to execute SQL a couple lines before. follow the same process: add or die(mysql_error()); $sql = mysql_query("SELECT * FROM forum_posts WHERE type='a' AND section_id='$sid' ORDER BY date_time DESC LIMIT 25") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/227259-code-warning-please-help/#findComment-1172314 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.