Re: php3/mySQL code help

by "Rossi Designs" <webmaster(at)rossidesigns.net>

 Date:  Sun, 4 Jun 2000 20:34:08 -0400
 To:  "Ken Guttman" <kguttman(at)ibm.net>,
<hwg-languages(at)hwg.org>
 References:  ibm
  todo: View Thread, Original
I usually prefer to use fetch row

instead of

while ($row = mysql_fetch_array($sql_result)) {
$airline = $row["airlines.name"];
$city = $row["cities.name"];

use 

while(list($airline,$city) = mysql_fetch_row($sql_result)) {

although your sql loses me a little, but I don't know too much about joins.

Rossi Designs
PO Box 1084
Holly Hill, FL 32125-1084
Phone : (904) 226-8979
URL : http://rossidesigns.net
----- Original Message ----- 
From: Ken Guttman <kguttman(at)ibm.net>
To: <hwg-languages(at)hwg.org>
Sent: Sunday, June 04, 2000 4:27 PM
Subject: php3/mySQL code help


| Hello,
|    I'm having a problem with a php3 script I'm writing. I've got three
| tables in a mySQL database: "schedule"=a list of 600 airline flights
| to/from my home airport, using codes for the airline and city name;
| "airlines"=a table that lists the code for each airline along with the
| full airline name; and "cities"=a table that lists the code for each
| city along with the full city name. All I want to do is list each
| airline along with the cities that it flies to from my airport, using
| the full names. I'm having trouble with formatting the data so that it
| produces this query in a simple table like this:
| American     Chicago
| American     Dallas/Fort Worth
| American     London
| American     Miami
| Delta           Atlanta
| etc. etc.
| 
| I know that the query I'm using works fine because I've tried it out
| verbatim in mysql and it produces the answer correctly. But I can't
| get anything except the column headings to show when I run the php3
| script on my website. My script is below. What am I doing wrong? Also,
| is it possible to format the query answer in the following way,
| listing the Airline just once in the table on one row?
| American     Chicago, Dallas/Fort Worth, London, Miami, etc.
| Delta            Atlanta, Cincinnati, etc.
| 
| <?php
| **various login stuff here**
| 
| // create SQL statement
| $sql = "select distinct airlines.name,cities.name from
| airlines,cities,schedule
| where airlines.code = schedule.airline and cities.code = schedule.city
| 
| order by airlines.name,cities.name";
| 
| // execute SQL query and get result
| $sql_result = mysql_query($sql,$connection)
| or die ("Couldn't execute query.");
| 
| // start results formatting
| echo "<table border=1>";
| echo "<tr><th>Airline</th><th>City</th></tr>";
| 
| // format results by row
| while ($row = mysql_fetch_array($sql_result)) {
| $airline = $row["airlines.name"];
| $city = $row["cities.name"];
| echo "<tr><td>$airline</td><td>$city</td></tr>";
| }
| 
| echo "</table>";
| 
| // free resources and close connection
| mysql_free_result($sql_result);
| mysql_close($connection);
| ?>
| 
| 

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA