Pawan_Agarwal Posted June 13, 2013 Share Posted June 13, 2013 Hello, I want to select all records in php code with mysql database. I have a table called "Customer", it has 2 fields "Name", "Number" How to select all records ? If I write select * from customer; It does not return me anything If I write select name,number from customer; It does return all records. Can some one tell me what to do here.............. Quote Link to comment https://forums.phpfreaks.com/topic/279120-select-statement/ Share on other sites More sharing options...
Maq Posted June 13, 2013 Share Posted June 13, 2013 Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/279120-select-statement/#findComment-1435768 Share on other sites More sharing options...
Pawan_Agarwal Posted June 14, 2013 Author Share Posted June 14, 2013 <?php $username = "*******"; $password = "*******"; $hostname = "*******"; $database = "*******";; $conn = mysql_connect($hostname, $username, $password, $database) or die("Could not connect: ".mysql_error()); if ($conn) { echo ("Connection is success<br>"); } else { echo ("Connection is failed"); } $selected = mysql_select_db("*****",$conn) or die("Could not select database"); if ($selected) { echo ("Connection is success to database<br><br>"); } else { echo ("Connection is failed"); } $result = mysql_query("SELECT * from student"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "Name: " . $row{'name'} . ":::::Class:" .$row{'class'}. ":::::Number:" .$row{'number'} . "<br>"; } ?> ---------------------------------------------------------------------------------------------------------------------------------------------------------------- After executing the code in PHP, I get no records display on my php page, I hope you are able to understand that the code I have written over here, Thanks for replying........... Quote Link to comment https://forums.phpfreaks.com/topic/279120-select-statement/#findComment-1435995 Share on other sites More sharing options...
Solution kicken Posted June 15, 2013 Solution Share Posted June 15, 2013 echo "Name: " . $row{'name'} . ":::::Class:" .$row{'class'}. ":::::Number:" .$row{'number'} . "<br>"; Please use tags when posting your code. Also I moved your topic as you posted in the MS SQL server forum, which is not what you are using. The way you access an array element is using square-brackets ([]), not curly's ({}) so the above line should be: echo "Name: " . $row['name'] . ":::::Class:" .$row['class']. ":::::Number:" .$row['number'] . "<br>"; Lastly, add error checking to your query so you can see if it is failing or not: $result = mysql_query("SELECT * from student"); if (!$result){ die('Could not run query: '.mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/279120-select-statement/#findComment-1436075 Share on other sites More sharing options...
Pawan_Agarwal Posted June 15, 2013 Author Share Posted June 15, 2013 That's it, I got my answer. Thank you so much for helping out...... Quote Link to comment https://forums.phpfreaks.com/topic/279120-select-statement/#findComment-1436114 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.