thedarkwinter Posted October 6, 2006 Share Posted October 6, 2006 re my earlier post about how im going back to working now (GRR)... this time im serious, this time i [i]DO[/i] mean it! ;DHuggie gets to work on the paginate - also... if the states are dynamic then, do as Huggie says with getting them from the db.also... me using [color=blue]br[/color] instead of cells is just downright lazy!!meant time: heres a short term easy solution involving streching the the size of the tables according to the total[code]<?phpmysql_connect("localhost", "root", "2cool4u");mysql_select_db("dddom");// the states: you can select this from db using group by, but if theres only 4 then just hardcode it$states = array("tamilnadu", "karala", "jammu", "centre", "delhi");$statesarrays = array();foreach ($states as $state){ $statesarrays[$state] = array(); // select all the cities(anumber?) matching the state $result = mysql_query("SELECT anumber FROM city1 WHERE state = '$state';"); $i =0; while ($row = mysql_fetch_row($result)) { $statesarrays[$state][$i++] = $row[0]; $total++; }}echo "<table border='1'><tr valign='top'>\n <td>";$i=0;$maxcolumns = 4;$maxrows = (ceil($total/$maxcolumns));foreach ($states as $state){ if ($i >= ($maxrows-2)) { $i=0; echo " </td><td>\n"; } echo "\n <b>$state<br></b>\n"; $i++; foreach ($statesarrays[$state] as $city) { echo " $city<br>\n"; $i++; if ($i == $maxrows) { $i=0; echo " </td><td>\n"; } } if ($i>0) { echo "<br>"; $i++; }}echo " </td></tr>\n</table>\n";?>[/code]back to work!have fun!!!tdw Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/page/2/#findComment-104989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.