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. 
}
?>

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
Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.