Conjurer Posted November 19, 2006 Share Posted November 19, 2006 Currently, to generate a table row from my query I am using:[code]foreach($row as $val) { echo "<td>$val</td>"; } echo "</tr>\n";[/code]That works great as long as I don't have too many columns in the query, but once it gets larger then it causes the output to scroll horizontally and messes up my page layout.I am wondering how I could change this - basically if I know I am querying on 15 columns but can only fit about seven columns how could I fix this to put a "</tr><tr><td>Continued</td>" in between value 7 and value 8? Do I need to do an i counter and increment it or what? If so what am I counting?Here is the more complete code I use now:[code]while ($row = mysqli_fetch_assoc($result)) { if (!$heading) //only do if header row hasn't been output yet { $heading = TRUE; //so we only do this once echo "<table>\n<tr>\n"; foreach ($row as $key =>$val) { echo "<th>$key</th>"; } echo "</tr>\n"; } if ($style=="odd") //set rows as even and odd $style = "even"; else $style = "odd"; echo "<tr class=\"$style\">"; foreach($row as $val) { echo "<td>$val</td>"; } echo "</tr>\n"; }//close while echo "</table>\n";} [/code]Thoughts or suggestions?Thanks! Link to comment https://forums.phpfreaks.com/topic/27805-how-can-you-split-a-row-returned-from-a-mysql-query/ Share on other sites More sharing options...
fert Posted November 19, 2006 Share Posted November 19, 2006 [code]$count=0;while($count<7){ echo "<td>{$row[$count]}</td>";}echo "</tr><tr>";while($count<14){ echo "<td>{$row[$count]}</td>";}[/code]this will output:|------|------|------|------|------|------|------|------|| | | | | | | |_____||------|------|------|------|------|------|------|| | | | | | | |--------------------------------------------------with the values in the cells Link to comment https://forums.phpfreaks.com/topic/27805-how-can-you-split-a-row-returned-from-a-mysql-query/#findComment-127217 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.