Jump to content

code warning please help


lmcgr44

Recommended Posts

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.