Jump to content


Photo

DISPLAYING problem???(colomn wise)


  • Please log in to reply
25 replies to this topic

#1 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 07:04 AM

Hello guys,

i am having one table called country and it has to field state, city?

example
table name country

state          city
-----------------
ABC            aaa
ABC            bbb
ABC            ccc
ABC            ddd

BBB            eee
BBB            fff
BBB            ggg ......

like this i am having 100 records

i want to display this in four colomn where each colomn should have 20 rows.

that is

AAA |BBB |CCC |
---- |--- |---- |
aaa  |eee|hhh  |
bbb  |fff  |iiii    |
ccc  |ggg|jjjj  |
....

Please help me guys i need soon.


#2 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 08:21 AM

i dont know the answer please help me,

#3 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 08:36 AM

hello guys please help me i am in trouble.

#4 HuggieBear

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

Posted 06 October 2006 - 08:41 AM

You need to get your information correct before we start.  For example, 4 rows of 20 is 80, so you don't want to display your remaining 20 records?

Also, can you not provide us with some actual data, rather than ABC BBB CCC etc, which incidently, it also looks like you got wrong.

Regards
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

#5 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 09:29 AM

Table name is india

state                city
----------------------
tamilnadu      chennai
tamilnadu      tricy
tamilnadu      madurai
tamilnadu      combatore
tamilnadu      salam
etc.....
karala          eranagulam
karala          munaru
karala          choain
etc..



#6 HuggieBear

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

Posted 06 October 2006 - 09:33 AM

OK, and are you just having a column for each state no matter how many rows there are?

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

#7 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 09:53 AM

i am having 80 rows  i want to display 4 colomn and 20 rows


#8 HuggieBear

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

Posted 06 October 2006 - 10:01 AM

And finally, is there going to be exactly 20 cities in each column (state).

Regards
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

#9 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 10:08 AM

No there may be 10 cities or 25 or any thing

if you have doubt plese see this site

www.gumtree.com

i want to display my records like this

#10 HuggieBear

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

Posted 06 October 2006 - 10:10 AM

Oh I see, it can be done, but it's going to take some time to get right... I have a script that does something similar, I can post the code for you tomorrow when I get home.

See here: http://www.dizzie.co.uk/php/pages2.php

Regards
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

#11 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 10:13 AM

the same way what i need please help me i need it urgent.

#12 HuggieBear

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

Posted 06 October 2006 - 10:21 AM

Yes, it's the same style that you need, I'll post the full code with columns tomorrow.

Regards
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

#13 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 10:24 AM

waiting for your coding man.



#14 thedarkwinter

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

Posted 06 October 2006 - 10:36 AM

Hi

I see HuggieBear is showing you a way to do it...

Below is a rough (untested - just type as i go) method that would pretty much do it in table format - with each state left to right as the table column headers, and then the cities listed below it...

you may find it useful

cheers,
tdw

<?php

mysql_connect("localhost", $usr, $pass);
mysql_select_db($db);

echo "<table><tr>"; // start the html table;

// the states: you can select this from db using  group by, but if theres only 4 then just hardcode it
$states = array("tamilnadu, karala, 3rdstate, 4thstate");
$statesarrays = array();
foreach ($states as $state)
{       // init and set each value blank $nbsp; for html output when there isnt a field
        for ($i=0;$i<20;$i++) { $statesarrays[$state][$i] = "&nbsp;"; }

        // add the state name as a heading in the table (started on line 6)
        echo "<td>$state</td>";

        // select all the cities matching the state, loop through and overwrite &nbsp; with the city
        $result = mysql_query("SELECT city FROM india WHERE state = '$state';");
        while ($row = mysql_fetch_row($result))
        { $statesarrays[$state][$i] = $row[0]; }
}

echo "</tr>"; // end ther tables header row

for ($i=0;$i<20;$i++) // loop up to twenty (max cities)
{
        echo "<tr>"; // start a table row
        foreach ($states as $state)
        {
                echo "<td>". $statesarrays[$state][$i] . "</td>"; // echo the city name in a cell
        }
        echo "</tr>"; // end the table row
}
echo "</table>"; // end the table

?>

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

#15 HuggieBear

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

Posted 06 October 2006 - 10:44 AM

I was going to post something like that, but the problem is that if tamilnadu has one city and karala has five, you end up with something like this...








tamilnadukarala
city1city1
city2
city3
city4
city5


The example provided the following format:








tamilnaducity3
city1city4
city5
Karala
city1State3
city2city1


Regards
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

#16 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 11:00 AM

i am trying it please wait

#17 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 11:43 AM

here the problem is there may be 10 cities in one state or 15 or 5 etc.. we cannot guess it so

i want

tamilnadu    state3
--------      ------
city1          city1
city2          city2
.              state4
.              ------ 
.              city1
.              city2
city10      .
              ..
karala      .
------      ;
city1        city16
city2
.
.
.
city10

like this it should want to come

#18 thedarkwinter

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

Posted 06 October 2006 - 11:49 AM

yip... that is the problem (if the numbers of cities are very uneven)...
i'm a man for funtionallity not looks (we'll just pretend that the code i wrote worked  :) )

What HuggieBear were saying earlier was cool - but i see he said he'll post it tomorrow :(

I'll have a play around just now and see if i can come up with a good way of doing it...


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

#19 HuggieBear

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

Posted 06 October 2006 - 11:55 AM

What HuggieBear were saying earlier was cool - but i see he said he'll post it tomorrow :(


Can't access my box at home from my desk at work :(

I'll try to post it early tomorrwo morning for you.

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

#20 rajmohan

rajmohan
  • Members
  • PipPipPip
  • Advanced Member
  • 169 posts

Posted 06 October 2006 - 11:56 AM

i give the table below the table name is city1 not only this values it may come countless... records i want to display it only 20 rows and remaining thing should come in next colomn.


INSERT INTO city1 VALUES (1, 'tamilnadu', '35005');
INSERT INTO city1 VALUES (1, 'tamilnadu', '35007');
INSERT INTO city1 VALUES (1, 'tamilnadu', '35950');
INSERT INTO city1 VALUES (1, 'tamilnadu', '35010');
INSERT INTO city1 VALUES (1, 'tamilnadu', '35952');
INSERT INTO city1 VALUES (1, 'tamilnadu', '36420');
INSERT INTO city1 VALUES (1, 'tamilnadu', '36201');
INSERT INTO city1 VALUES (1, 'Karala', '35016');
INSERT INTO city1 VALUES (1, 'Karala', '35611');
INSERT INTO city1 VALUES (1, 'Karala', '36502');
INSERT INTO city1 VALUES (1, 'Karala', '35954');
INSERT INTO city1 VALUES (1, 'Karala', '36830');
INSERT INTO city1 VALUES (1, 'Karala', '36507');
INSERT INTO city1 VALUES (1, 'jammu', '35020');
INSERT INTO city1 VALUES (1, 'jammu', '35204');
INSERT INTO city1 VALUES (1, 'jammu', '35031');
INSERT INTO city1 VALUES (1, 'jammu', '35956');
INSERT INTO city1 VALUES (1, 'jammu', '36426');
INSERT INTO city1 VALUES (1, 'jammu', '35040');
INSERT INTO city1 VALUES (1, 'Centre', '\n35960');
INSERT INTO city1 VALUES (1, 'jammu', '35044');
INSERT INTO city1 VALUES (1, 'jammu', '35045');
INSERT INTO city1 VALUES (1, 'delhi', '35051');
INSERT INTO city1 VALUES (1, 'delhi', '35453');
INSERT INTO city1 VALUES (1, 'delhi', '35962');
INSERT INTO city1 VALUES (1, 'delhi', '35055');
INSERT INTO city1 VALUES (1, 'delhi', '36853');
INSERT INTO city1 VALUES (1, 'delhi', '36322');
INSERT INTO city1 VALUES (1, 'delhi', '36526');





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users