affordit Posted January 19, 2008 Share Posted January 19, 2008 The code below has an error somewhere but I can't see it can anyone help? It is supposed to retrieve all the data from my table and display it in a table but all I get is No Results found! <?php include("dbinfo.inc.php"); include("dbinfo.inc.php"); mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "select * from contacts"; $result =($query); if (($result)||(mysql_errno == 0)) { echo "<table width='100%' border='1'><tr>"; if (mysql_num_rows($result)>0) { //loop thru the field names to print the correct headers $i = 0; while ($i < mysql_num_fields($result)) { echo "<th>". mysql_field_name($result, $i) . "</th>"; $i++; } echo "</tr>"; //display the data while ($rows = mysql_fetch_array($result,MYSQL_ASSOC)) { echo "<tr>"; foreach ($rows as $data) { echo "<td align='center'>". $data . "</td>"; } } }else{ echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>"; } echo "</table>"; }else{ echo "Error in running query :". mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86729-solved-select-query-problem/ Share on other sites More sharing options...
marcus Posted January 19, 2008 Share Posted January 19, 2008 $result = mysql_query($query) or die(mysql_error()); lol Quote Link to comment https://forums.phpfreaks.com/topic/86729-solved-select-query-problem/#findComment-443214 Share on other sites More sharing options...
affordit Posted January 19, 2008 Author Share Posted January 19, 2008 Thanks did not see that but did not solve the problem still getting the same thing Quote Link to comment https://forums.phpfreaks.com/topic/86729-solved-select-query-problem/#findComment-443218 Share on other sites More sharing options...
Ken2k7 Posted January 19, 2008 Share Posted January 19, 2008 Wow...a few things: 1. Don't include the same file twice. Errors can happen. So: include("dbinfo.inc.php"); include("dbinfo.inc.php"); Should be: include("dbinfo.inc.php"); 2. mysql isn't a constant unless you defined it to be. It's a string. mysql_connect(mysql,$username,$password); Should be: mysql_connect('mysql',$username,$password); 3. This is what mgallforever said. $result =($query); Should be: $result = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/86729-solved-select-query-problem/#findComment-443219 Share on other sites More sharing options...
affordit Posted January 19, 2008 Author Share Posted January 19, 2008 Thanks All I guess I been at it to long for one day. Quote Link to comment https://forums.phpfreaks.com/topic/86729-solved-select-query-problem/#findComment-443222 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.