|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Way to display special formated html tables from mySQL
Hi to all. I am trying to write an application that builds dynamically pages with mySQL data. There is a list of hotels in 23 countries and at about 70 - 80 towns. The query i want to sxecute has to do this: select all the hotels in a country and displays them in a html table like this:
TOWN1 hotel1 prise1 prise2 description hotel2 prise1 prise2 hotel3 prise1 prise2 TOWN2 hotel1 prise1 prise2... and so on. The problem is that i get an array by the mysql_fetch_array method, but when I print them every hotel is printed with the town over it. I need the town once and all the hotel in it listed after it. I've done it in some way with lots of queries using one function, but I have a problem - the table that is desplayed on the page must be separated into 2 equal parts (columns). Something like: TOWN1 TOWN3 hotel1 prise1 prise2 hotel1 prise1 prise2 description description hotel2 prise1 prise2 hotel2 prise1 prise2 description description TOWN2 TOWN4 hotel1 prise1 prise2 hotel1 prise1 prise2 description description hotel2 prise1 prise2 hotel2 prise1 prise2 description description.......... I wrote the following code which cannot separete the tables printed into 2 columns (have in mind that I am absolutely new to PHP - started 4-5 days ago - and the code might look stupid to you): //function function query_special ($id1,$id2) { $query= "select * from cities, hotels where hotels.country_id='$id1' and cities.country_id='$id1' and cities.city_id=hotels.city_id and cities.city_id='$id2' and hotels.city_id='$id2' "; $result = mysql_query($query); while ($row=mysql_fetch_array($result)) { echo("<tr><td>$row[name]</td><td>$row[double_euro]</td><td>$row[single_euro]</td></tr><tr><td colspan=3>$row[description]</td></tr>n"); } } //PAGE echo "<table border='1'>"; echo "<td bgcolor=#999999 colspan=3>Moskou</td>"; query_special (1,1); echo "<td bgcolor=#999999 colspan=3>Sint Peterburg</td>"; query_special (1,2); echo "</table>"; ?>The args in the query_special() are - country_id and city_id. I've read 2 big books but wasn't able to find a reasonable solution. If somebody has done something like this before and can sugest a solution or a source I ca read in, I would be very grateful! Thanks! Valery |
|
#2
|
|||
|
|||
|
RE: Way to display special formated html tables from mySQL
I see a couple of things wrong with your code.
The first is that you are making a query for EVERY hotel. instead of one and then printing the results. I would move the following code into the main page, instead of in query_special(). you could alos put all of the printing code in query_special(). Now to your problem. You need to do some nesting to get what you want. $CityString = ""; while ($row=mysql_fetch_array($result) { if($CiyString !== $row[]) { // Print city header $CityString = $row[] } // Print Hotel Detail } This is a rough idea. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Way to display special formated html tables from mySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|