Re: Style questions: variable in echo, preparing sql queries

From: Date: Thu, 23 Nov 2000 06:19:13 +0000
Subject: Re: Style questions: variable in echo, preparing sql queries
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-26795@lists.php.net to get a copy of this message
On Thu, 23 Nov 2000, Brian Clark wrote: > Hello Chris, > > (CL == "Chris Lott") chris@intranet.dist-ed.uaf.edu writes: > > CL> Two questions about style: > CL> > CL> 1) echo "PartID is $PartID"; > CL> seems to work fine. Is there a reason that I see others use: > CL> echo "PartID is " . $PartID; > > Well if they're trying to be `proper' they might as well use single > quotes around 'Part ID is' because there is nothing to be > interpolated. > > Personally, I just stick to echo "PartID is $PartID"; > > CL> 2) When querying a db, I see users who do something like: > CL> $sql = "select foo from bar"; > CL> $results = mysql_query("$sql") > > No need for the quotes. > > $results = mysql_query($sql) > > CL> Is there a reason not to just put the SQL code directly in the function: > CL> $results=mysql_query("select foo from bar") ? > > No. Separating the SQL from the execution is AFAIK just for > readability. Well, not necessarily. What if your query is dependent on values entered by the user and is built dynamically? F'rinstance, I just chucked this together: $query10 = "SELECT level, code_id, ascii_desc from icd10 WHERE "; if ($source != 'code') { $query10 .= "ascii_desc like '%$text%' "; } else { $query10 .= "code_id like '%$text%'"; } switch ($codes10req) { case 'diag': $query10 .= " AND (LEFT(code_id,1) = 'S' OR LEFT(code_id,1) = 'T')"; break; case 'ecode': $query10 .= " AND (LEFT(code_id,1) = 'V' OR LEFT(code_id,1) = 'W'"; $query10 .= " OR LEFT(code_id,1) = 'X' OR LEFT(code_id,1) = 'Y')"; break; } $query10 .= ' ORDER BY code_id'; to allow user definition of the field to search in and user definition of a set of possible exclusions. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#26795) next »