piet Posted January 12, 2008 Share Posted January 12, 2008 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/85712-reading-from-2-tables/ Share on other sites More sharing options...
Barand Posted January 12, 2008 Share Posted January 12, 2008 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' "); Quote Link to comment https://forums.phpfreaks.com/topic/85712-reading-from-2-tables/#findComment-437461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.