avo Posted September 2, 2006 Share Posted September 2, 2006 HI allim just testing writing some functions but why will this not return the second or third $sql if the varible isset[code]function Select($contents,$table,$name1,$postname1,$name2,$postname2,$limit){ if (isset($contents) && isset($table) && isset($postname1)){ return $sql = "SELECT ".$contents." FROM ".$table." WHERE ".$name1." = ".$postname1.""; } if (isset($name2) && isset($postname2) ){ return $sql.=" AND ".$name2." = ".$postname2.""; } if (isset($limit)){ return $sql.="LIMIT ".$limit.""; }}[/code][quote]$test=Select('*',test_table,username,testname,'username2','testname2','2');echo($test);[/quote]?> Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 2, 2006 Share Posted September 2, 2006 try this..[code]function Select($contents,$table,$name1,$postname1,$name2,$postname2,$limit) { if (($contents !== '') && ($table !== '') && ($postname1 !== '')) { return $sql = "SELECT ".$contents." FROM ".$table." WHERE ".$name1." = ".$postname1.""; } if (($name2 !== '') && ($postname2 !== '') ) { return $sql.=" AND ".$name2." = ".$postname2.""; } if ($limit !== '')) { return $sql.="LIMIT ".$limit.""; }}[/code]i have changed to !== '' as this checks if there is a value but i think isset() will always return true because it is set at the top wether there is a value or not, i've also corected the if statement enclosures..RegardsLiam Quote Link to comment Share on other sites More sharing options...
avo Posted September 2, 2006 Author Share Posted September 2, 2006 Hi thanks i used !empty()i've realized what i should have done .[code]function Select($contents,$table,$name1,$postname1,$name2,$postname2,$limit){ if (!empty($contents) && !empty($table) && !empty($postname1)){ $sql = "SELECT ".$contents." FROM ".$table." WHERE ".$name1." = ".$postname1.""; } if (!empty($name2) && !empty($postname2) ){ $sql.=" AND ".$name2." = ".$postname2.""; } if (!empty($limit)){ $sql.=" LIMIT ".$limit.""; } return $sql;}$test=Select('*','',test_table,testname,'','','1');echo($test);[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.