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
https://forums.phpfreaks.com/topic/73363-solved-cant-print-data-from-mysql/
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>";
?>

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.