Jump to content

[SOLVED] Can't print data from mysql.


Rommeo

Recommended Posts

Hello

i m new at php and mySql. i have a table which has ;

 

userid(int/autoincrement)||name||surname||info(text)||pass(md5)

 

And to see the some selected fields ( for to try ) i have this code :

<?php
include 'database.php';
$result=mysql_query("SELECT * FROM userstable") || die ( mysql_error() );

echo "<table border='1'>";
echo "<tr> <th>userid</th> <th>name</th> </tr>";
while($row = mysql_fetch_array( $result )) 	
	{
echo "<tr><td>"; 
echo $row["userid"];
echo "</td><td>"; 
echo $row["name"];
echo "</td></tr>"; 
	}
echo "</table>";
?>

 

But code does not work and i get this error :

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /showresults.php on line 15.

 

Can anyone help me ? And is there any other way for to take the datas one by one and to print them ?

Thanks in advance.

Link to comment
Share on other sites

Try this:

 

<?php
include 'database.php';
$sql = "SELECT * FROM userstable";
$results = mysql_query($sql) or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>userid</th> <th>name</th> </tr>";
while($row = mysql_fetch_array( $results )) 	
	{
echo "<tr><td>"; 
echo $row["userid"];
echo "</td><td>"; 
echo $row["name"];
echo "</td></tr>"; 
	}
echo "</table>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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