Its however you prefer it (or whatever is easier to type usually). sprintf is usable, depends on if you have a c or perl background, and its second nature. For me, I use editplus on windows which gives color coding (www.editplus.com), if I do $query = "select abc,def,ghi from table1,table2". $another_table ." where abc='". $a ."'"; I can immediately see the $another_table, and $a are variables. Use a color coded editor - it makes life a lot easier. Lawrence. -----Original Message----- From: Moriyoshi Koizumi [mailto:[EMAIL PROTECTED]] Sent: July 26, 2001 10:28 AM To: [EMAIL PROTECTED] Subject: [PHP] how do you write queries in php codes? (was Re: [PHP] Why doesn't this simple query work?) yes, both of yours make the same result too, and are clean :-) and i wonder what the best way is, to put queries into php code... there's a more complicated sample, $a=addslashes($a); $b=addslashes($b); $c=addslashes($c); if( $another_table ) { $another_table=','.$another_table; } $query = "select abc,def,ghi from table1,table2 $another_table where abc='$a' and def='$b' and ghi='$c' "; and i prefer because i often confuse php variables with columns if( $another_table ) { $another_table=','.$another_table; } $query = sprintf( 'select abc,def,ghi from table1,table2 %s where abc="%s" and def="%s" and ghi="%s"', $another_table, addslashes($a), addslashes($b), addslashes($c) ); but i think the latter loses some good php features... then, does anyone have good idea? [EMAIL PROTECTED] wrote: > how about > > $location = addslashes($location); > $query = "select shoodID from shoots where location = '$location'"; > > or > > $query = "select shoodID from shoots where location = '". > addslashes($location) ."'"; > > > Both are \'clean\' :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]