patsypoopa Posted April 19, 2008 Share Posted April 19, 2008 I've just posted a problem and it was solved however now i've got another problem with displaying the solution Oh and i'm still a newbie! Right, i've got a loop which SHOULD display columns and records from a table. In a format like this for each record: Name: Blah Age: Bleh It does this fine for the first record but for the 2nd record it only has the cell so its showing like this: : Blah : Bleh Hope someone has the solution thanks either way $sql = "SELECT * FROM $chosencollection"; $result = mysql_query($sql); $result2 = mysql_query($sql); $cols_num = mysql_num_fields($result2); ?> <h1>View Collection</h1> <? echo "<p><h2>" . $collectionnametitle ."</h2></p>"; while($row = mysql_fetch_row($result)) { foreach($row as $cell) { $col = mysql_fetch_field($result2); $col->name = str_replace("_", " ", $col->name); echo "<b>{$col->name}</b>: $cell<br>"; } echo "<br>"; } Link to comment https://forums.phpfreaks.com/topic/101887-solved-display-problems/ Share on other sites More sharing options...
Northern Flame Posted April 19, 2008 Share Posted April 19, 2008 well first off, there is a few HTML errors in your coding, replace: echo "<p><h2>" . $collectionnametitle ."</h2></p>"; with: echo "<h2>" . $collectionnametitle ."</h2>"; try this code: $sql = "SELECT * FROM $chosencollection"; $result = mysql_query($sql); $result2 = mysql_query($sql); $cols_num = mysql_num_fields($result2); ?> <h1>View Collection</h1> <? echo "<p><h2>" . $collectionnametitle ."</h2></p>"; while($row = mysql_fetch_row($result)) { foreach($row as $cell) { $col = mysql_fetch_field($result2); $col_name = str_replace("_", " ", $col->name); echo "<b>$col_name</b>: $cell<br>"; } echo "<br>"; } Link to comment https://forums.phpfreaks.com/topic/101887-solved-display-problems/#findComment-521430 Share on other sites More sharing options...
Barand Posted April 19, 2008 Share Posted April 19, 2008 try <?php $sql = "SELECT * FROM $chosencollection"; $result = mysql_query($sql); echo '<h1>View Collection</h1>'; echo "<h2>$collectionnametitle </h2>"; while($row = mysql_fetch_assoc($result)) { foreach ($row as $fld => $value) { echo "$fld : $value <br />"; } echo '<br />' ; } Link to comment https://forums.phpfreaks.com/topic/101887-solved-display-problems/#findComment-521434 Share on other sites More sharing options...
patsypoopa Posted April 19, 2008 Author Share Posted April 19, 2008 Thanks Barand that worked perfect! Link to comment https://forums.phpfreaks.com/topic/101887-solved-display-problems/#findComment-521603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.