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:
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  
Old February 25th, 2002, 11:49 AM
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, 07: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!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway