0

Any idea how I can do this?

This is what I tried, and it doesn't work:

$query="SELECT bookingdata.*, users.* FROM bookingdata, users WHERE bookingdata.userid = users.userid";
		
$sql=mysql_query($query);

while ($row = mysql_fetch_array($sql)) {
	$id=$row['id'];
	$userid=$row['userid'];
        $bookingdata=$row['bdate'];......etc. etc. 
}
?>
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by diafol
0

Well you want to JOIN but you're not JOINing

(side note, don't use * be explicit about the fields you want.

SELECT u.userid, bd.bdate, bd.id FROM bookingdata bd JOIN users u ON bd.userid = u.userid
0

This is an INNER JOIN. A more syntactically correct way (*I think*) would be:

$query="SELECT bookingdata.*, users.* FROM bookingdata INNER JOIN users ON bookingdata.userid = users.userid";
 
$sql=mysql_query($query);
 
while ($row = mysql_fetch_array($sql)) {
	$id=$row['id'];
	$userid=$row['userid'];
        $bookingdata=$row['bdate'];......etc. etc.
}

If you have duplicate names some fields in both tables (not including 'id'), you'll need to name them and provide aliases using the AS keyword - however this situation is unlikely.

//Sorry Shawn - simultaneous post & yes - use of * should usually be discouraged.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.