rajmohan Posted October 6, 2006 Share Posted October 6, 2006 Hello guys,i am having one table called country and it has to field state, city?example table name countrystate city-----------------ABC aaaABC bbbABC cccABC dddBBB eeeBBB fffBBB ggg ......like this i am having 100 recordsi 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. Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/ Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 i dont know the answer please help me, Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104841 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 hello guys please help me i am in trouble. Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104845 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104847 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 Table name is indiastate city----------------------tamilnadu chennaitamilnadu tricytamilnadu maduraitamilnadu combatoretamilnadu salametc.....karala eranagulamkarala munarukarala choainetc.. Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104863 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 OK, and are you just having a column for each state no matter how many rows there are?Huggie Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104865 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 i am having 80 rows i want to display 4 colomn and 20 rows Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104869 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 And finally, is there going to be exactly 20 cities in each column (state).RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104874 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 No there may be 10 cities or 25 or any thingif you have doubt plese see this sitewww.gumtree.comi want to display my records like this Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104877 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 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.phpRegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104878 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 the same way what i need please help me i need it urgent. Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104880 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 Yes, it's the same style that you need, I'll post the full code with columns tomorrow.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104885 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 waiting for your coding man. Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104886 Share on other sites More sharing options...
thedarkwinter Posted October 6, 2006 Share Posted October 6, 2006 HiI 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 usefulcheers,tdw[code]<?phpmysql_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] = " "; } // 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 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 rowfor ($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?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104894 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 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...[table][tr][td][b]tamilnadu[/b][/td][td][b]karala[/b][/td][/tr][tr][td]city1[/td][td]city1[/td][/tr][tr][td] [/td][td]city2[/td][/tr][tr][td] [/td][td]city3[/td][/tr][tr][td] [/td][td]city4[/td][/tr][tr][td] [/td][td]city5[/td][/tr][/table]The example provided the following format:[table][tr][td][b]tamilnadu[/b][/td][td]city3[/td][/tr][tr][td]city1[/td][td]city4[/td][/tr][tr][td] [/td][td]city5[/td][/tr][tr][td][b]Karala[/b][/td][td] [/td][/tr][tr][td]city1[/td][td][b]State3[/b][/td][/tr][tr][td]city2[/td][td]city1[/td][/tr][/table]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104899 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 i am trying it please wait Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104912 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 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 city1city2 city2. state4. ------ . city1. city2city10 . ..karala .------ ;city1 city16city2...city10like this it should want to come Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104949 Share on other sites More sharing options...
thedarkwinter Posted October 6, 2006 Share Posted October 6, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104954 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 [quote author=thedarkwinter link=topic=110667.msg447926#msg447926 date=1160135399]What HuggieBear were saying earlier was cool - but i see he said he'll post it tomorrow :([/quote]Can't access my box at home from my desk at work :(I'll try to post it early tomorrwo morning for you.Huggie Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104958 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 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'); Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104959 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104963 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 it should be displayed in next page or it should be splited common for the four colomn Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104974 Share on other sites More sharing options...
thedarkwinter Posted October 6, 2006 Share Posted October 6, 2006 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.[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;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";?>[/code]outputs[code]<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>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104980 Share on other sites More sharing options...
rajmohan Posted October 6, 2006 Author Share Posted October 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104984 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 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 [b]<[/b][b]br>[/b] 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 Quote Link to comment https://forums.phpfreaks.com/topic/23153-displaying-problemcolomn-wise/#findComment-104985 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.