Jump to content

DISPLAYING problem???(colomn wise)


rajmohan

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.