Jump to content

Recommended Posts

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);

 

Link to comment
https://forums.phpfreaks.com/topic/224994-multiple-selection/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162105
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162127
Share on other sites

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)";

Link to comment
https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162508
Share on other sites

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"

 

 

Link to comment
https://forums.phpfreaks.com/topic/224994-multiple-selection/#findComment-1162524
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.