Jump to content

Archived

This topic is now archived and is closed to further replies.

sk1tL1L

mysql_fetch_array question

Recommended Posts

Hello, i've got abit of a problem
[code]
  <?php
include ("config.php");

// Retrieve data from database
$sql= "SELECT * FROM messages WHERE to='$member'";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%"><? echo $rows['from']; ?></td>
<td width="40%"><? echo $rows['message']; ?></td>

</tr>
</table>

<?php
}
mysql_close();
?>[/code]

Whic displays an error:
[code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\xampp\htdocs\TFP\messages.php on line 51[/code]

I'm Trying to make my own PM system, it will be great if you can help me with this.

Share this post


Link to post
Share on other sites
echo out the query and run it in phpmyadmin I suspect you are retunring 0 rows.

Share this post


Link to post
Share on other sites
If the query were returning zero rows, the OP wouldn't get an error, but the while loop wouldn't execute. That error usually occurs when the query has a syntax error. Change the mysql_query() to:
[code]<?php $result=mysql_query($sql) or die("There is a problem with the query: $sql<br>" . mysql_error()); ?>[/code]
Check the error that prints, and fix the problem...

Ken

Share this post


Link to post
Share on other sites
make the $member variable '".$member."'. i dont like code that isnt like that. or you can add { and } i think.

Share this post


Link to post
Share on other sites
ok thanks everyone,
[code]<?php $result=mysql_query($sql) or die("There is a problem with the query: $sql<br>" . mysql_error()); ?>[/code]
that helped me out!

Share this post


Link to post
Share on other sites

×

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.