PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 25th, 2002, 12:49 PM
valeryve valeryve is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 valeryve User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old March 29th, 2002, 08:25 PM
jkofsky jkofsky is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 jkofsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Way to display special formated html tables from mySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek