nottoolate Posted January 19, 2011 Share Posted January 19, 2011 When I try to select more than one value for my report, only one value shows. I tried a few things, but I'm not having any luck. Here is the form code: <td style="text-align: right">Job Type:</td> <td> <select name="job_type" multiple="multiple" size="3"> <option value="0" selected>ALL</option> {section name=jt loop=$job_type_list} <option value="{$job_type_list[jt][0]}">{$job_type_list[jt][1]}</option> {/section} </select> </td> Here is the other code: //All IIS Object Code is to be encapsulated in the execute_object function function execute_object($tab){ if ((isset($_POST['job']) and isset($_POST['job_type']) and isset($_POST['child_type']) and isset($_POST['job_status']) and isset($_POST['child_status']) and isset($_POST['ou']) and isset($_POST['child_ou']) and isset($_POST['pm']) and isset($_POST['child_pm']) and isset($_POST['dm']) and isset($_POST['child_dm']) and isset($_POST['customer']) and isset($_POST['end_date'])) or (isset($_SESSION['report_job']) and isset($_SESSION['report_job_type']) and isset($_SESSION['report_child_type']) and isset($_SESSION['report_job_status']) and isset($_SESSION['report_child_status']) and isset($_SESSION['report_ou']) and isset($_SESSION['report_child_ou']) and isset($_SESSION['report_pm']) and isset($_SESSION['report_child_pm']) and isset($_SESSION['report_dm']) and isset($_SESSION['report_child_dm']) and isset($_SESSION['report_customer']) and isset($_SESSION['report_end_date']))) { //Include functions include $GLOBALS['include_path']."penta.job.functions.php"; include $GLOBALS['include_path']."display.functions.php"; include $GLOBALS['include_path']."report.functions.php"; //Get report parameters if (isset($_POST['job'])){ $job_id = $_POST['job']; } else { $job_id = $_SESSION['report_job']; } if (isset($_POST['job_type'])){ $job_type = $_POST['job_type']; } else { $job_type= $_SESSION['report_job_type']; } if (isset($_POST['child_type'])){ $child_type = $_POST['child_type']; } else { $child_type= $_SESSION['report_child_type']; } if (isset($_POST['exclude_type'])){ $exclude_type = 1; } else { if(isset($_SESSION['report_exclude_type'])){ $exclude_type = $_SESSION['report_exclude_type']; } else { $exclude_type = 0; } } if (isset($_POST['job_status'])){ $job_status = $_POST['job_status']; } else { $job_status= $_SESSION['report_job_status']; } if (isset($_POST['child_status'])){ $child_status = $_POST['child_status']; } else { $child_status= $_SESSION['report_child_status']; } if (isset($_POST['ou'])){ $ou_id = $_POST['ou']; } else { $ou_id = $_SESSION['report_ou']; } if (isset($_POST['child_ou'])){ $child_ou_id = $_POST['child_ou']; } else { $child_ou_id = $_SESSION['report_child_ou']; } if (isset($_POST['pm'])){ $pm_id = $_POST['pm']; } else { $pm_id = $_SESSION['report_pm']; } if (isset($_POST['child_pm'])){ $child_pm_id = $_POST['child_pm']; } else { $child_pm_id = $_SESSION['report_child_pm']; } if (isset($_POST['dm'])){ $dm_id = $_POST['dm']; } else { $dm_id = $_SESSION['report_dm']; } if (isset($_POST['child_dm'])){ $child_dm_id = $_POST['child_dm']; } else { $child_dm_id = $_SESSION['report_child_dm']; } if (isset($_POST['customer'])){ $cus_id = $_POST['customer']; } else { $cus_id = $_SESSION['report_customer']; } if (isset($_POST['sort_by_cust'])){ $sort_by_cust = 1; } else { if(isset($_SESSION['report_sort_by_cust'])){ $sort_by_cust = $_SESSION['report_sort_by_cust']; } else { $sort_by_cust = 0; } } if (isset($_POST['end_date'])){ $edate = $_POST['end_date']; } else { $edate = $_SESSION['report_end_date']; } $job_type = implode(",",$_POST['job_type']); //Prepare to output report $filename = "Project Review Report.xls"; if (isset($_POST['print'])){ //Prepare the output file header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); header("Pragma: public"); } else { //Save the report parameters to enable printing from the preview $_SESSION['report_job'] = $job_id; $_SESSION['report_job_type'] = $job_type; $_SESSION['report_child_type'] = $child_type; $_SESSION['report_exclude_type'] = $exclude_type; $_SESSION['report_job_status'] = $job_status; $_SESSION['report_child_status'] = $child_status; $_SESSION['report_ou'] = $ou_id; $_SESSION['report_child_ou'] = $child_ou_id; $_SESSION['report_pm'] = $pm_id; $_SESSION['report_child_pm'] = $child_pm_id; $_SESSION['report_dm'] = $dm_id; $_SESSION['report_child_dm'] = $child_dm_id; $_SESSION['report_customer'] = $cus_id; $_SESSION['report_sort_by_cust'] = $sort_by_cust; $_SESSION['report_end_date'] = $edate; //Output a print button at the start of the preview preview_print_button("load_object.php?&object=52.2"); } //Get the list of jobs based on the given criteria $job_list = report_job_list($job_id, $job_type, $child_type, $exclude_type, $job_status, $child_status, $ou_id, $child_ou_id, $pm_id, $child_pm_id, $dm_id, $child_dm_id, $cus_id, $sort_by_cust, $selected_by); //Set the max script execution time to ensure it can finish based on the number of jobs $num_jobs = $job_list->RecordCount(); set_time_limit(60 + ($num_jobs * 30)); //Parse the template $template = $GLOBALS['reports_path']."report52.2.htm"; $default_logo = "report52.2_files/image001.gif"; $hdr = null; $ftr = null; parse_template($template, $default_logo, $hdr, $ftr); Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/ Share on other sites More sharing options...
AbraCadaver Posted January 19, 2011 Share Posted January 19, 2011 You must define the select name as an array with []: <select name="job_type[]" multiple="multiple" size="3"> Then to use it you will have to loop through it: foreach($_POST['job_type'] as $job_type) { echo $job_type; } Or just to get a list you can implode() it: implode(',', $_POST['job_type']); Also, you are using alot of isset() on the $_POST variables. All $_POST variables will be set when the form is submitted even if they are empty (except checkboxes). Try using !empty() or don't do anything if empty values are OK. Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162105 Share on other sites More sharing options...
nottoolate Posted January 19, 2011 Author Share Posted January 19, 2011 Thanks. I'm not the original coder and just making modifications, which makes this a little more difficult. I now get this error: Fatal error: Call to a member function RecordCount() it says that the SQL command is not properly ended...not sure what that is about. Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162127 Share on other sites More sharing options...
nottoolate Posted January 20, 2011 Author Share Posted January 20, 2011 My report is still only showing one of the two selections. When I use implode, I get ORA-00933. The $job_type is equal to a field within my database. I'm assuming the comma in the implode is causing my function to not work properly? Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162471 Share on other sites More sharing options...
BlueSkyIS Posted January 20, 2011 Share Posted January 20, 2011 echo the SQL so you can see it and we can see it. otherwise we're all just guessing. is job_type a string and not a number? if so, you'll need to quote the strings $job_types = "'". implode("','", $_POST['job_type'])."'"; $sql = "SELECT id FROM sometable WHERE job_type IN ($job_types)"; Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162508 Share on other sites More sharing options...
nottoolate Posted January 20, 2011 Author Share Posted January 20, 2011 Yes, $job_type is a string not a number When I use implode, (SQL command not properly ended).. $sql = "select job.job_id as ID, job.name as NAME, job.cus_id AS CUS_ID, customer.name AS CUS_NAME, job.par_job_id as PARENT_ID from job join customer on job.cus_id = customer.cus_id where job.jt_cd = 1,2 order by job.job_id" Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162524 Share on other sites More sharing options...
BlueSkyIS Posted January 20, 2011 Share Posted January 20, 2011 job.jt_cd = 1,2 should be job.jt_cd IN (1,2) Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162596 Share on other sites More sharing options...
nottoolate Posted January 20, 2011 Author Share Posted January 20, 2011 I've changed it to 'IN' and I no longer receive an error, but its still showing all the jobs instead of the jobs associated with the values 1 & 2. Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162612 Share on other sites More sharing options...
nottoolate Posted January 21, 2011 Author Share Posted January 21, 2011 anymore input? Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162982 Share on other sites More sharing options...
BlueSkyIS Posted January 21, 2011 Share Posted January 21, 2011 don't use the join. Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1163061 Share on other sites More sharing options...
nottoolate Posted January 24, 2011 Author Share Posted January 24, 2011 Ok. I've fixed the problem. I've modified implode to $job_type = implode(" 'OR job.jt_cd='", $_POST['job_type']); Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1164404 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.