Jump to content

Multiple table queries


fontener

Recommended Posts

Hi all, I need some help as I am new to PHP ... I am trying to display a table of data from a query of multiple tables. Anyway, let's say I have a table called "radiostations".. and within that table is a "formatID" ... this "formatID" is also shared with a table called "formats" which corresponds to a given "format" .. I dont want to limit my query to only that format... but when i display the results, instead of showing the "formatID" I want to show the corresponding "format". You're probably going  :wtf: ... but any help would be appreciated. I have attached a picture for visual help.

 

In other words, right now I am querying table "radiostations" to display all 'radiostations' and corresponding info and setting variables for "call_letters, formatID"... etc. but i dont want to display the formatID, rather it's relational value...

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/192752-multiple-table-queries/
Share on other sites

Ok, I'm only getting one row to show with said method... any ideas? here's the full code

 

<?php
$color1 = "#CCFFCC"; 
$color2 = "#CEC5A6"; 

$result =mysql_query( "select r.*,f.format,m.md_name, p.city, p.state_province from station r,format f,md m, postal p where r.format_id = f.format_id and r.md_id = m.md_id and r.postal_id = p.postal_id");  
if (!$result) {    echo("<p>Error performing query: " .         mysql_error() . "</p>");    exit();  }
  while ($row = mysql_fetch_array($result))
  {
            $callabcs = $row["call_letters"];
            $station = $row["station_name"];
            $link = $row["station_website"];
            $phone = $row["station_phone"];   
            $md = $row["md_name"];
            $pd = $row["pd_name"];   
            $format = $row["format"];
            $level = $row["level"];   
            $city = $row["city"];
            $local = $row["state_province"];
            $notes = $row["additional_notes"];
}
?>

<table cellpadding="0" cellspacing="0" cellpadding="0" border="0" class="megatable"><tr><th>Call Letters</th><th>Station ID</th><th>Phone</th><th>MD</th><th>PD</th><th>Format</th><th>Level</th><th>City</th><th>Province</th><th>Notes</th></tr>
<?php
$row_count = 0; 
$row_color = ($row_count % 2) ? $color1 : $color2; 
echo "<tr><td bgcolor=\"$row_color\" id=\"hundo\">$callabcs</td><td bgcolor=\"$row_color\" id=\"hundo\"><a href=\"$link\">$station</a></td><td bgcolor=\"$row_color\" id=\"hundo\">$phone</td><td bgcolor=\"$row_color\" id=\"hundo\">$md</td><td bgcolor=\"$row_color\" id=\"hundo\">$pd</td><td bgcolor=\"$row_color\" id=\"hundo\">$format</td><td bgcolor=\"$row_color\" id=\"level\">$level</td><td bgcolor=\"$row_color\" id=\"hundo\">$city</td><td bgcolor=\"$row_color\" id=\"hundo\">$local</td><td bgcolor=\"$row_color\" id=\"hundofity\">$notes</td></tr>"; 
$row_count++;
?>
</table>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.