Page 1 of 1

Join Question... :)

Posted: Sun Oct 20, 2002 1:11 am
by Zoram

Code: Select all

$query = "
	SELECT r.proId, r.title, r.rating, r.review, p.name, p.pic1
	FROM Review r 
	RIGHT JOIN Products p
		ON r.proId = p.id
	ORDER BY RAND() limit 1;";
Is there something wrong with this? I can't get any results back... And once i do, would i use something like

Code: Select all

$name = $rowї'p.name'];
Or something else?

Thanks

Posted: Sun Oct 20, 2002 3:22 am
by ReDucTor
it will actually be $row['name'] if you fetch it as an assositive array

Posted: Sun Oct 20, 2002 3:23 am
by Coco
not sure if this would make any difference?:
A table reference may be aliased using tbl_name AS alias_name or tbl_name alias_name:
mysql> SELECT t1.name, t2.salary FROM employee AS t1, info AS t2
-> WHERE t1.name = t2.name;



also (not a bug, but recommended):
RIGHT JOIN works analogously as LEFT JOIN. To keep code portable across databases, it's recommended to use LEFT JOIN instead of RIGHT JOIN.

Posted: Mon Oct 21, 2002 4:26 am
by twigletmac
Not sure what you mean by 'I can't get any results back', does the query not return the results you want or does it just not work at all, ie. show an error?

For error checking make sure that you use mysql_error():

Code: Select all

@$result = mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');
Remove the semi-colon ( ; ) after the LIMIT clause as it is not necessary - LIMIT 1 instead of LIMIT 1;.

Mac