...

View Full Version : A mysql_fetch_array error :(



markman
06-15-2005, 08:46 AM
Hey all.
I am having some trouble with a mysql_fetch_array statement in a script (bellow) that should make news from a message board appear on the screen.


<?php
include("nav.php");
?>
<td width="610" valign="top" border="1">
<table width="610" cellpading="0" cellspacing="0" align="left" border="0">
<tr>
<td width='610' height='9' bgcolor='#000000' valign='top'></td>
</tr>
<tr>
<td width='610' height='13' background='images/index_06.gif' valign='top'></td>
</tr>
<tr>
<td>
<table width='610' border='0' rowspan='0' background='images/index_08.gif' >
<?php
include("connections/forum.php");
$get = mysql_query("SELECT * FROM `threads` WHERE `type` = 'announcement' ORDER BY id");
while ($array = mysql_fetch_array($get)) {
$poster = $array['poster'];
$get2 = mysql_query("SELECT * FROM users WHERE username='$poster'");
while ($array2 = mysql_fetch_array($get2)) {
echo "<tr>
<td width='15%'><b><u>$array[poster]</u></b></a></td>
<td width='84%' align='right'>$array[posttime]</td>
</tr>
<tr>
<td align='center' valign='middle'>
<img src='images/admin.jpg' alt='' border='2' width='80' height='80' />
</td>
<td width='84%' valign='top'><b><u>$array[title]</u></b><br /><br /><br /><br />\n
$array[message]<br /><br />
________________________________________________________________
</td>
</tr>
";
}
}
?>
</table>
</td>
</tr>
<tr>
<td width='610' height='13' background='images/index_06.gif' valign='top' border='1'></td>
</tr>
</td>
</table>
</td>
<td width="10" height="542" bgcolor="#000000" valign="top" border="1"></td>
<td width="127" height="2" colspan="0" valign="top" background="images/index_04.gif" rowspan="16" align="top">
<table cellpading="0" cellspacing="0" align="top" border="1">
<tr>
<td valign="top" rowspan="2" border="1">
<?php
if (!$_SESSION['userid']) {
?>
<center><b>Log in</b></center>
<form method="POST" action="login2.php">
Username :<br />
<input type="text" name="username" title="username" id="username" size="15" /><br />
Password :<br />
<input type="text" name="password" title="password" id="password" size="15" />
<input type="submit" value="Log in" /><input type="reset" value="reset" />
</form>
<?php
} else {
?>
Welcome back : <br /><b><?php echo $_SESSION[username]; ?></b><br /><br />
<img src="<?php echo $_SESSION[avatar]; ?>" alt="" border="2" /><br /><br />
<a href="modifyprofile.php?id=<?php echo $_SESSION[userid]; ?>">
Modify your profile</a>
<?php
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

Line 21 is where the error is, it says it isn't a valid mySql ressource :eek:
Line 21 is :
$get2 = mysql_query("SELECT * FROM users WHERE username='$poster'");

doyle_loader
06-15-2005, 01:27 PM
I would try this:
$get2 = "SELECT * FROM users WHERE username='$poster'";

I don't use mysql_query(); for any of my select statements. But I am fairly new at this game. :rolleyes:

Cheers,

Chris

Kid Charming
06-15-2005, 05:20 PM
You have to use mysql_query() -- that's how the statement gets sent to the database. Without it, you've just got a string variable floating around. I do prefer, though, to keep my statements in a separate variable and send that to mysql_query() -- that way, it's easy to echo the query to see exactly what you're sending.

For some reason, your query is failing, so $get2 is being set to FALSE instead of to a resource. Try echoing your query to see what's being sent and adding 'or die(mysql_error())' to the end of your mysql_query() call to get MySQL's error message regarding the query.

doyle_loader
06-15-2005, 06:13 PM
Oh Geez. I didn't even realize what I posted haha.

I always place SELECT * Blah Blah in a variable then use mysql_query();

Like this:


$sql = "SELECT CourseName, TeacherName, NotesTitle, FileName
From Notes
Where CourseName = '$CourseName'
Order by NotesTitle Asc";

$result = mysql_query($sql);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum