Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.