OriginalSunny Posted March 24, 2006 Share Posted March 24, 2006 Hi,just a quick question. I have created a table with headings for each column in my database. I now want to display everything from my database in php. I have got the following code: $connect = connect_to_db("cnn.inc"); $query = "select * from products"; $result = mysql_query($query,$connect) or die("sql_del: ".mysql_error($connect));I now want to display all the items. The only way i can think is to do some sort of an array to go through each entry in the database. I don'd know exaclty how to do this properly. I can display each item seperately using:$prod = mysql_result($result1,0,0);echo "$prod";but as you know this is a silly and time consuming way to do it for each entry. As i am fairly new to php i don't know how to do it properly.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/5728-getting-all-info-from-database/ Share on other sites More sharing options...
shocker-z Posted March 24, 2006 Share Posted March 24, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$connect = connect_to_db("cnn.inc");$query = "select * from products";$result = mysql_query($query,$connect)or die("sql_del: ".mysql_error($connect));while ($row = mysql_fetch_array($result)) {echo($row['field1'] $row['fieald2'].'<br>');}[/quote]That will loops thru and instead of field1 field2 change them to when ever the columns are called in your table.That should do the job mate :) Quote Link to comment https://forums.phpfreaks.com/topic/5728-getting-all-info-from-database/#findComment-20424 Share on other sites More sharing options...
OriginalSunny Posted March 25, 2006 Author Share Posted March 25, 2006 Thanks. It works. But the trouble i am having now is that all the headings for my table are being output and then the values in the columns are being output below the table. I want them in the following format:OrderID 200 233Surname Smith Terry...The code i am using is: echo "<table cellspacing='20'>"; echo "<tr>OrderID</tr><br>"; while($row = mysql_fetch_array($result)) { echo "<td>"; echo($row['orderID'].'<br>'); echo"</td>"; } echo "<tr>Surname</tr><br>"; while($row1 = mysql_fetch_array($result)) { echo "<td>"; echo($row['surname'].'<br>'); echo"</td>"; }I cant see what i have done wrong here. In addition to this only the values for orderID are output and the values stored for surname are not ouput unless i get rid of the array displaying the orderID's. Your help would be appreciated.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/5728-getting-all-info-from-database/#findComment-20447 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.