Rommeo Posted October 15, 2007 Share Posted October 15, 2007 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 More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 No message from mysql_error() ? Link to comment https://forums.phpfreaks.com/topic/73363-solved-cant-print-data-from-mysql/#findComment-370136 Share on other sites More sharing options...
simcoweb Posted October 15, 2007 Share Posted October 15, 2007 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 https://forums.phpfreaks.com/topic/73363-solved-cant-print-data-from-mysql/#findComment-370139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.