Jump to content


Photo

Fetch Arrays


  • Please log in to reply
1 reply to this topic

#1 creativkook

creativkook
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 01 April 2006 - 03:29 AM

I keep getting this error that my fetch arrays are not a valid resource for the two located near the bottom of my code, the ones hilighted. Can anyone see what I'm doing wrong? I'm trying to pull out entries for a simple forum, using three database tables that tie together. Thanks!

<?php

require("dbheader.php");

$topic = mysql_fetch_array(mysql_query("SELECT topic FROM topics WHERE topicid = $_GET[topicid]"));
echo(mysql_error());

$title = $topic['topic'];

$entries = mysql_query("SELECT *, UNIX_TIMESTAMP(eventTime) AS utime FROM entry WHERE topicid = $_GET[topicid]");

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR...ml4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title); ?></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<?php

$entry = mysql_fetch_array($entries);
$userid = $entry['userid'];
$user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE userid = $userid"));
$edate = date("l, F jS", $entry['utime']);
$etime = date("g:i a", $entry['utime']);

while($entry)
{
echo("<div class='display'");

echo("<table cellpadding='3' cellspacing='3'>");
echo("<tr>");
echo("<td>");
echo("<p>$user[username]</p>");
echo("<p>$edate at $etime</p>");
echo("</td>");
echo("<td>");
echo("<p>$entry[entry]</p>");
echo("</td>");
echo("</tr>");

echo("</div>");
}

?>

</body>
</html>

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 01 April 2006 - 05:16 AM

You should break up your queries to narrow down errors. When you get that error usually it is a problem with your query. try enclosing the value in your where clause like below.

$sql = "SELECT topic FROM topics WHERE topicid = ".$_GET[topicid]."";
$result = mysql_query($sql) or die (mysql_error());

Ray





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users