Jump to content

Archived

This topic is now archived and is closed to further replies.

rajmohan

DISPLAYING problem???(colomn wise)

Recommended Posts

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!  ;D

Huggie 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]
<?php

mysql_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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.