Forum Moderators: coopster

Message Too Old, No Replies

building an sql query

syntax

         

jackson

1:45 am on Oct 18, 2003 (gmt 0)

10+ Year Member



I picked this up as part of a previous thread:
$sql = mysql_query("SELECT id, colour FROM category_two");
(... some more stuff)

The question here is, what are the significant differences in building a query as given above and something like this?

$query = "SELECT cat_id,cat_name FROM category ORDER BY cat_name" ;
$result = mysql_query($query);
(... some more stuff)

The query in the first instance seems so much more efficient yet, the second method seems so commonplace. Emphasis here being on the query structure NOT the content part following the SELECT statement.

TIA

jatar_k

1:56 am on Oct 18, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I always build my query into a var and then do
$query = mysql_query($q);

it makes it very simple to echo the exact query if need be for debugging. It also makes it more straight forward for me when I am building very large dynamic queries.

One thing at a time, no need to get everything done in one shot. ;)

lorax

3:22 pm on Oct 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I do as jatar_k suggests. I like to build my code such that trouble-shooting is made easier. Then after I've proofed the code I could trim it down if I wanted to - but more often than not I leave it alone.

I'm not building million record databases intended for millions of users in a day either.