Dysan Posted November 16, 2007 Share Posted November 16, 2007 Can data in the database be displayed without using a while loop. Obviously only one record will get displayed. mysql_select_db("db", $con); $result = mysql_query("SELECT * FROM details"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/77674-display-data-without-while-loop/ Share on other sites More sharing options...
alecks Posted November 16, 2007 Share Posted November 16, 2007 If you know there is only one row that you are getting (if query is something like '.... WHERE `id` = [specific id]', or you know for certain that your table only has one row) then you can just do $result = mysql_fetch_array(mysql_query("SELECT * FROM `details`")); echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; otherwise you need the while() to loop through all the rows. Quote Link to comment https://forums.phpfreaks.com/topic/77674-display-data-without-while-loop/#findComment-393221 Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 well I using a for loop to display all the records, if a condition is true. How do I display the data from the database now? oreach ($contents as $id=>$qty) { } Quote Link to comment https://forums.phpfreaks.com/topic/77674-display-data-without-while-loop/#findComment-393224 Share on other sites More sharing options...
alecks Posted November 17, 2007 Share Posted November 17, 2007 If there are multiple rows of data, then you need to use the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/77674-display-data-without-while-loop/#findComment-393231 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.