Jump to content

functions


andyd34

Recommended Posts

I have a generic function for searches but I want to add addition fields which are optional. For some reason I thought doing the following would arrow me to do this.

 


function browse($mode, $type, field1 = NULL, $field2 = NULL) {

}

 

then to call the function

 


$search_new = browse($_POST['new'], $_POST['games']);
$search_new_arcade = browse($$_POST['new'], $_POST['games'], $_POST['arcade']);

 

but this doesnt work, I have seen it done before but cant remember where. Can someone please help so I dont have to call differant functions to output the same things

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/173666-functions/
Share on other sites

This is not hte actual function as its over 200 lines long but its more or less what the function is about, the $field1, $field2 etc are supposed to be optional and do not require a value or so i thought

 

function browse($mode, $type, $field1 = NULL, $field2 = NULL) {


  if($mode=='new') {
  
    if($type=='games') {
     $sql = "SELECT * FROM table WHERE cat = '$type'";
        
     if($field=='arcade' ? " AND sub_cat = $field" : '');
     $query = mysql_query($sql)
    }
   if($type=='software') {
    $sql = "SELECT * FROM table WHERE cat = '$type'";

   }
  }

}

Link to comment
https://forums.phpfreaks.com/topic/173666-functions/#findComment-915440
Share on other sites

yes i know to call the variables is

 

if($field1 ? $str[] = "cell = '$field1'" : '');
if($field2 ? $str[] = "cell = '$field2'" : '');
if($field3 ? $str[] = "cell1 = '$field3'" : '');
if($field4 ? $str[] = "cell2 = '$field4'" : '');
if($field5 ? $str[] = "cell3 = '$field5'" : '');

$where = implode(' AND ', $str);

$sql = "SELECT * FROM table";
if($where ? $sql .= " WHERE $where" : '');

the porblem was for some strange reason it was returning an error. I deleted my history and cookie and the error has cleared. Strange!!

Link to comment
https://forums.phpfreaks.com/topic/173666-functions/#findComment-915459
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.