[thelist] php query

Liam Delahunty ldelahunty at britstream.com
Thu Feb 20 05:33:08 CST 2003


Andrew Maynes

>if I am selecting from one table the records that are related to an id of
>another table what is the best way to do this?

Something like the following should suffice in MySQL

select table2.col_name from table1, table2 where table2.reference_id =
table1.id


so the php could be...

$query = "select table2.col_name from table1, table2 where
table2.reference_id = table1.id";

if ($result = mysql_query($query, $connection) or die ("Error line: "
.__LINE__  . ""))	{
	while ($myrow = mysql_fetch_row($result)){
		$col_name = $myrow[0];
		print ("$col_name<br>");
	}
}

HTH

Kind regards, Liam Delahunty, Mega Products Limited
http://www.megaproducts.co.uk/ web design, programming, e-commerce
http://www.onlinesales.co.uk/ Open Source PHP/MySQL E-commerce App.
http://www.britstream.com/ Hosting/ Domain Names From UKP 7.50 p.a.




More information about the thelist mailing list