Jump to content


Photo

mysql_fetch_array question


  • Please log in to reply
4 replies to this topic

#1 sk1tL1L

sk1tL1L
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 03 October 2006 - 09:29 AM

Hello, i've got abit of a problem
  <?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();
?>

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

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

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 03 October 2006 - 10:04 AM

echo out the query and run it in phpmyadmin I suspect you are retunring 0 rows.
follow me on twitter @PHPsycho

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 October 2006 - 11:54 AM

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:
<?php $result=mysql_query($sql) or die("There is a problem with the query: $sql<br>" . mysql_error()); ?>
Check the error that prints, and fix the problem...

Ken

#4 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 03 October 2006 - 12:06 PM

make the $member variable '".$member."'. i dont like code that isnt like that. or you can add { and } i think.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#5 sk1tL1L

sk1tL1L
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 07 October 2006 - 01:26 AM

ok thanks everyone,
<?php $result=mysql_query($sql) or die("There is a problem with the query: $sql<br>" . mysql_error()); ?>
that helped me out!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users