Jump to content

reading from 2 tables


piet

Recommended Posts

Hi, i am pretty new at this and would appreciate any help.

i need to read info from 2 tables. first table holds info about events and the second one holds venue details. the "venue_name" in the first table will determine the 2nd query. i suspect the problem is in this line. "$venue_name=$venue_name;"

i get output for the first query fine, but not the second.can anyone please tell me what i am doin wrong?

mysql_connect($server,$username,$password);
@mysql_select_db($database) or die ("Unable to connect to the database");

$id=$_POST['id'];
$do=mysql_query ("SELECT id,venue_name,event_date FROM calendar_events WHERE id='$id' ");
$x=mysql_num_rows($do);
if ($x>0) {
while ($row = mysql_fetch_array($do, MYSQL_ASSOC)) {
  $venue_name.=$row["venue_name"];
  $event_date.=$row["event_date"];
  $id.=$row["id"];
}
;}
echo "&total=".$x."&venue_name=".$venue_name."&event_date=".$event_date."&id=".$id;

$venue_name=$venue_name;
$do=mysql_query ("SELECT venue,street,town FROM venues WHERE venue='$venue_name' ");
$x=mysql_num_rows($do);
if ($x>0) {
while ($row = mysql_fetch_array($do, MYSQL_ASSOC)) {
  $venue.=$row["venue"];
  $street.=$row["street"];
  $town.=$row["town"];
}
;}
echo "&venue=".$venue."&street=".$street."&town=".$town;
?>

Link to comment
https://forums.phpfreaks.com/topic/85712-reading-from-2-tables/
Share on other sites

use a single query

<?php
$do=mysql_query ("SELECT c.id, c.venue_name, c.event_date, v.street, v.town 
                    FROM calendar_events c
                        INNER JOIN venues v ON c.venue_name = v.venue
                    WHERE c.id='$id' ");

Link to comment
https://forums.phpfreaks.com/topic/85712-reading-from-2-tables/#findComment-437461
Share on other sites

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.