Re: A real problem

From: Date: Mon, 26 Apr 2004 20:05:50 +0000
Subject: Re: A real problem
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-184696@lists.php.net to get a copy of this message
From: "Daniel Clark" <dclark@nwlink.com> > If I was displaying it. :-) > Here is a "ruff" guess. > > <? > $query = "SELECT id, name FROM shop_brands"; > $result = mysql_query($query) or die("error in query - $query > ".mysql_error()); > > while($row = mysql_fetch_row($result)) { > > list($brand_id, $brand_name) = $row; > > $query2 = "SELECT * FROM shop_models WHERE brand_id = $brand_id"; Not sure what you're trying to accomplish here, but anytime you have nested SELECT queries like this, you're begging for it to be replaced with a single SELECT query with a JOIN. SELECT sb.id, sb.name, sm.* FROM shop_brands sb, shop_models sm WHERE sb.id = sm.brand_id Now you have everything you need in a single, more efficienct, query. ---John Holmes...

« previous php.general (#184696) next »