Jump to content

mysql_fetch_array question


sk1tL1L

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.
Link to comment
https://forums.phpfreaks.com/topic/22843-mysql_fetch_array-question/
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

Archived

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

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