Jump to content


Photo

DISPLAYING problem???(colomn wise)


  • Please log in to reply
25 replies to this topic

#21 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 12:05 PM

OK, are you going to paginate the results?

So if you have 4 columns of 20 rows, that's a maximum of 80 table cells, but there's 85 rows in your database, what do you want to do with the other 5 results.

What are each of the columns in your table?  Can I also make modifications to the database table structure or not?

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#22 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 12:20 PM

it should be displayed in next page or it should be splited common for the four colomn

#23 thedarkwinter

thedarkwinter
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationLondon

Posted 06 October 2006 - 12:37 PM

okay i'm going to leave this to Huggie (i'm supposed to be working too)... but here is something you can look at if you like:

when it hits 80 though it will make a 5th column though so it will need work.



<?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;
foreach ($states as $state)
{
        if ($i >= 19) { $i=0; echo "  </td><br>\n"; }
        echo "  <b>$state<br></b>\n";
        $i++;
        foreach ($statesarrays[$state] as $city)
        {
                echo "    $city<br>\n";
                $i++;
                if ($i == 20) { $i=0; echo "  </td><td>\n"; }
        }
        echo "<br>";

}
echo "  </td></tr>\n</table>\n";
?>

outputs
<html>
<table border='1'><tr valign='top'>
  <td>  <b>tamilnadu<br></b>
    35005<br>
    35007<br>
    35950<br>
    35010<br>

    35952<br>
    36420<br>
    36201<br>
<br>  <b>karala<br></b>
    35016<br>
    35611<br>

    36502<br>
    35954<br>
    36830<br>
    36507<br>
<br>  <b>jammu<br></b>
    35020<br>

    35204<br>
    35031<br>
    35956<br>
  </td><td>
    36426<br>
    35040<br>

    35044<br>
    35045<br>
<br>  <b>centre<br></b>
    35960<br>
<br>  <b>delhi<br></b>
    35051<br>

    35453<br>
    35962<br>
    35055<br>
    36853<br>
    36322<br>
    36526<br>

<br>  </td></tr>
</table>

Remember - if you don't figure it out yourself, you'll probably forget it tomorrow :)

#24 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 12:45 PM

yes this is what i needed i really thank you guy.

one more doubt if it cross more then 80 can we move to next page whether it is possible

#25 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 12:55 PM

We're using a similar method I think, except I'm getting the states from the database, and I'm putting each city in its own table cell as opposed to using <br> tags.  But that's for formatting preference.

I'm not sure how I'm going to get them to paginate accurately, but I'm working on it.

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#26 thedarkwinter

thedarkwinter
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationLondon

Posted 06 October 2006 - 01:10 PM

re my earlier post about how im going back to working now (GRR)... this time im serious, this time i DO 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 br 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

<?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";
?>

back to work!

have fun!!!
tdw
Remember - if you don't figure it out yourself, you'll probably forget it tomorrow :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users