Jump to content

fetch MySQL content, error ?


thaidomizil

Recommended Posts

Hello

 

i want to fetch the content from my MySQL db for one table and show it on a page, i'm using this code:

<?php include("inc/connect.php"); ?>
<?php
$result = $_REQUEST['result'];
?>

<?php
$query = mysql_query("select * from listtest order by id asc");
while($result = mysql_fetch_array($query))
{
?>
  <tr>
    <td><?php echo $result['id']; ?></td>
    <td><?php echo $result['code']; ?></td>
    <td align="center"><a href="edit.php?id=<?php echo $result['id']; ?>">View</a></td>

    <td align="center"> </td>
  </tr>
<?php } ?>

 

it's throwing me this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in 32qgtf.php on line 30

 

What am i doing wrong ?

 

/Edit: line 29/30 is the mysql query / fetch.

Link to comment
https://forums.phpfreaks.com/topic/248138-fetch-mysql-content-error/
Share on other sites

It seems like your query is failing. Try changing your query line to

 

$query = mysql_query("select * from listtest order by id asc") or die(mysql_error());

 

and post if there is an error (and what the error is)

 

Note: or die() is never good to use in production. its ok for debugging purposes only.

If you have phpmyadmin log into there, select your table and then in the mySql box copy and paste the query in.. "select * from listtest order by id asc"  What happens?  Any results?

 

What if you View>Source of the page.  Is anything showing up then?  It could be you have an issue with your html

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.