cleeclee Posted November 16, 2012 Share Posted November 16, 2012 Hi i'm trying to display a table thru mysql. Just learnt to do so and i haven't got a clue what is wrong with the code. In line 19 the error is that 'mysql_numrows() expects parameter 1 to be resource'. Can i get some help as to what to correct it with? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $host="localhost"; $username="root"; $password=""; $database="energy"; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tablename"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td><font face="Arial, Helvetica, sans-serif">Value1</font></td> <td><font face="Arial, Helvetica, sans-serif">Value2</font></td> <td><font face="Arial, Helvetica, sans-serif">Value3</font></td> <td><font face="Arial, Helvetica, sans-serif">Value4</font></td> <td><font face="Arial, Helvetica, sans-serif">Value5</font></td> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"field1"); $f2=mysql_result($result,$i,"field2"); $f3=mysql_result($result,$i,"field3"); $f4=mysql_result($result,$i,"field4"); $f5=mysql_result($result,$i,"field5"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> </tr> </table> <?php $i++; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/270768-error-while-displaying-mysql-table/ Share on other sites More sharing options...
Barand Posted November 16, 2012 Share Posted November 16, 2012 And do you have a table in your database called "tablename"? Link to comment https://forums.phpfreaks.com/topic/270768-error-while-displaying-mysql-table/#findComment-1392828 Share on other sites More sharing options...
AyKay47 Posted November 16, 2012 Share Posted November 16, 2012 Debug the query using mysql_error Link to comment https://forums.phpfreaks.com/topic/270768-error-while-displaying-mysql-table/#findComment-1392833 Share on other sites More sharing options...
cleeclee Posted November 16, 2012 Author Share Posted November 16, 2012 Hi i've decided to keep it simple. Here's what i did. Without the while loop i'm only able to display 1 line of data. I'd like to display the other lines too, so i used the loop and i have the same error msg as in my original post. "Warning: mysql_fetch_array() expects parameter 1 to be resource" Link to comment https://forums.phpfreaks.com/topic/270768-error-while-displaying-mysql-table/#findComment-1392843 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2012 Share Posted November 16, 2012 And do you have a table in your database called "tablename"? Well? Do you? Link to comment https://forums.phpfreaks.com/topic/270768-error-while-displaying-mysql-table/#findComment-1392845 Share on other sites More sharing options...
cleeclee Posted November 16, 2012 Author Share Posted November 16, 2012 Got it figured out! thanks it was a small mistake in my codes. sorry to trouble you guys. Thank you! Link to comment https://forums.phpfreaks.com/topic/270768-error-while-displaying-mysql-table/#findComment-1392846 Share on other sites More sharing options...
AyKay47 Posted November 16, 2012 Share Posted November 16, 2012 Got it figured out! thanks it was a small mistake in my codes. sorry to trouble you guys. Thank you! Great, what was the issue? Link to comment https://forums.phpfreaks.com/topic/270768-error-while-displaying-mysql-table/#findComment-1392899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.