RE: [PHP] database (slightly ot)

From: Date: Thu, 08 May 2003 15:15:07 +0000
Subject: RE: [PHP] database (slightly ot)
Groups: php.general 
Request: Send a blank email to php-general+get-146854@lists.php.net to get a copy of this message
> -----Original Message----- > From: Ryan A [mailto:ryan@jumac.com] > Sent: 08 May 2003 15:46 > > Hi, > I have been going through the code that the last developer > left behind and I > see this: > > if(isset($sname)&&$sname && isset($surl)&&$surl ) > { > if($db->query("Select 1 from $site_table where (nick='$sname' or > address='$surl') and userid = $userid ") && $db->get_num_rows() > > 0 ) > { > $error = "A site with this nick/address already exists for this > user.<br> Pleasy try again with a different nick/address."; > } > > > I have two questions (kind of newbie so watch out) > > 1)Whis is it "select 1 from...." isnt it supposed to be > "select * from..." Only if you want to select all fields. Here, the "select 1" is basically returning a 1 if the where condition is met, and nothing if not -- so the result can be used as an operand to the && operator. > 2) A little confused here "&& $db->get_num_rows() > 0 )" how > can you assign > a pointer like that? Huh? I see no assignments here. Nor yet a pointer (which PHP doesn't have anyway!). Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#146854) next »