Return Multiple Values from picklist using $_REQUEST

Hello I have an existing picklist that i am trying to tweak - I am making it into a multiselect and trying to return multiple values

I have been able to accomplish the first part by adding select ‘multiple’ but when i submit it only returns results for the last value selected.

Here is the code for the form (Left out the picklists that do not need to be multiple select)

<td align="center" valign="top">
<? // base64_encode(base64_encode( 'test1'))?>
<br />
<br />
<form id='report_form' action="driverreport_sd.php" method="post" name="report_form">
<!--<div class="criteria_div">-->
<table align="center" class="table_border" cellpadding="5" cellspacing="0" width="80%">
<tr>
<td align="right" class="first_td">
Status:
</td>
<td align="left">
<select multiple name='Status' id='Status'>

<? $statuslist=$ObjReport->ObjStatus->get_Status_List(); while($status=mysql_fetch_object($statuslist)) { if($status->Status=="Please Select") { ?>

<option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>>
<?=$status->Status?></option>
<? } else { ?>
<option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>>
<?=$status->Status?></option>
<? } } ?>
</select>
</td>
</tr>


<td align="center" colspan="2">
<input type="hidden" id='sort_by' name='sort_by' value="<?=$_REQUEST['sort_by']?>" />
<input type="hidden" name='search_val' id='search_val' value="<?=$_REQUEST['search_val']?>" />
<input type="hidden" name='search_by' id='search_by' value="<?=$_REQUEST['search_by']?>" />
<input type="hidden" name="report_submited" value='report_submited' />
<button type="submit" id="report_submited" name="" value='submit'>Submit</button>
</td>

and here is the return request

                <?    
                    if($_REQUEST['report_submited'])    
                    {
                        
                        
                    
                        
                    
                        $ReportData=$ObjReport->generate_report($_REQUEST['Status'],$_REQUEST['School'],$_REQUEST['Campaign'],$_REQUEST['State'],$_REQUEST['Stdtype'],$_REQUEST['Primbad'],$_REQUEST['Rep'],$_REQUEST['From_Date'],$_REQUEST['To_Date'],$_REQUEST['sort_by'],$_REQUEST['search_by'],$_REQUEST['search_val']);
                        $currentTotalRow=mysql_num_rows($ReportData);
                        if($currentTotalRow>0)
                        {
                        
                ?>

Any suggestions would be appreciated

Thanks!

Do not use $_REQUEST. You cannot determine the true source of the input when you use this shorthand variable. Use $_POST, $_GET, or $_COOKIE directly as required by context.

By convention, a request made by the client to look up data should be handled with GET, requests that change data on the server should be handled with POST and cookies information shouldn’t be allowed to infiltrate either.

(off topic - I’m really tired of discourse interpreting the underscore character as the start of an italic section. Can this be changed?)

Try a backslash escape or wrapping shorter code in single backticks eg.
$\_POST
$_POST

`$_POST`
$_POST

That’ll work.

You’ll need to add brackets to the select name attribute.

<select multiple name='Status[]' id='Status'>

This will make $_POST[‘Status’] an array.
I do not know how $ObjReport->generate_report() is going to handle this. Never used that.

Hi followed both suggestions added the -

Your form is being submitted by POST, so you’ll need to access the data from the $_POST array:

$_POST['Status'] // etc

If you can’t modify the coding in generate_report to handle an array you might try this. I have not attempted to join result sets before so this is just something to test.

$ReportData = "";
foreach($_POST['Status'] as $Status):
    $ReportData .= $ObjReport->generate_report($Status,$_POST['School'],$_POST['Campaign'],$_POST['State'],$_POST['Stdtype'],$_POST['Primbad'],$_POST['Rep'],$_POST['From_Date'],$_POST['To_Date'],$_POST['sort_by'],$_POST['search_by'],$_POST['search_val']);
endforeach;

Thank you everyone for the suggestions - tried changing REQUEST to POST and still getting 0 results back also tried Drummin’s suggestion and same deal but not sure if I am modifying the code correctly
Here is the entire php code:

    <?
session_start();
include_once('../php_class/driverreport.class.php');
$ObjReport=new report();
if(isset($_SESSION['Login_Person']))
{
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="SHORTCUT ICON" href="../images/vtigercrm_icon.ico">

<link rel="stylesheet" type="text/css" href="../css/report.css">
<script src="../js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="../js/autoMask.js"> </script>
<script type="text/javascript" src="../js/common_function.js"> </script>
<? include_once('../includes/calender_scripts.php'); ?>

<script>

$(function() {
var dates1 = $(".ctrDOB").datepicker({
//minDate: 0 , // Use to do not give previous date in selection
showOn: "button",
buttonImage: "images/cal.gif",
buttonImageOnly: true,
changeYear: true,
changeMonth: true,
yearRange: "2013",
dateFormat: 'mm-dd-yy',
onSelect: function() {
$(this).change();
}
});
});

jQuery(function($){
$(".ctrDateMask").mask("99-99-9999",{placeholder:" "});
});

jQuery(function($){
$(".ctrnumber").mask("99999",{placeholder:" "});

});



$(document).ready(function(){

$(".sort").click(function(){
$("#sort_by").val($(this).attr('id'));
$("#search_val").val($("#search_value").val());
//alert($("#sort_by").val());
document.report_form.submit();
//alert($(this).attr('id'));
//return false;
});


$("#search").click(function(){
$("#search_val").val($("#search_value").val());
document.report_form.submit();
});

$("#search_by_option").change(function(){
$("#search_by").val($(this).val());
});

$("#Status").change(function(){

//if($("#Status").val()==="Please Select")
//alert($(this).val());

});

$("#report_form").submit(function(){
var msg='';
if($("#From_Date").val()=="" && ($("#Campaign").val()=="Please Select")) // || $("#Campaign").val()=="ALL"))
{
msg+='- From Date Can not be blank. \n';
}
if($("#To_Date").val()=="" && ($("#Campaign").val()=="Please Select")) // || $("#Campaign").val()=="ALL"))
{
msg+='- To Date Can not be blank. \n';
}
if($("#Status").val()=="Please Select")
{
msg+='- Status Can not be blank. \n';
}
if($("#School").val()=="Please Select")
{
msg+='- School Name Can not be blank. \n';
}
if($("#Campaign").val()=="Please Select")
{
msg+='- Campaign Can not be blank. \n';
}
if($("#State").val()=="Please Select")
{
msg+='- State Can not be blank. \n';
}
if($("#Rep").val()=="Please Select")
{
msg+='- Rep Can not be blank. \n';
}

if(msg=="")
{
/*
$("#report_submited").click(function(){
//alert('hello');
$.ajax({url:"report_result.php?report_submited=report_submited&Status="+$("#Status").val(),success:function(result){
//alert(result);
$("#report_result_div").html(result);

}});
});*/
return true;

}
else
{

alert("Following information is required! \n\n" +msg);
return false;
}
});

$("#chart").click(function(){
//$("#pie_chart").css('display','block');
$("#pie_chart").css('visibility','visible');
$("#chart_close").css('visibility','visible');
});

$("#chart_close").click(function(){
$("#pie_chart").css('visibility','hidden');
$("#chart_close").css('visibility','hidden');

});


});



</script>
</head>

<body>


<table class="container" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" style="padding:0px">
<? include("../includes/header.php");?>

</td>
</tr>
<tr>
<td colspan="2" style="padding:0px">
<div id='linkheader' dir="ltr" >

<?
if(isset($_SESSION['Login_Person']))
{
?>

<a href="../php_class/login_controller.php?Logout=<?=$_SESSION['Login_Person']?>" >Logout</a>
&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;

<?
}
?>
<a href="search_student.php">Search Student</a>

<?
if($_SESSION['user_detail']->User_Type==1)
{
?>
&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;
<a href="manage_user.php?">Manage User</a>
&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;
<a href="add_user.php">Add User</a>
&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;
<a href="report_sd.php">Report</a>
&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;
<a href="updatereport_sd.php">Updated Info Report</a>
&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;
<a href="badaddress_sd.php">Bad Address Report</a>
<?
}
if($_SESSION['user_detail']->User_Type==3)
{
?>
&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;
<span style="color:#FFFFFF">Driver Report</span>
&nbsp;

<?
}



if($_POST['report_submited'])
{
?>

&nbsp;
<div class='divider'></div>
&nbsp;&nbsp;
<a href="driverexport_data.php?pageno=<?=$_POST['pageno']?>&Status=<?=$_POST['Status']?>&School=<?=$_POST['School']?>&Campaign=<?=$_POST['Campaign']?>&State=<?=$_POST['State']?>&Stdtype=<?=$_POST['Stdtype']?>&Primbad=<?=$_POST['Primbad']?>&Rep=<?=$_POST['Rep']?>&From_Date=<?=$_POST['From_Date']?>&To_Date=<?=$_POST['To_Date']?>&sort_by=<?=$_POST['sort_by']?>&search_by=<?=$_POST['search_by']?>&search_val=<?=$_POST['search_val']?>">Driver Export</a>
<?
}
?>

</div>
</td>
</tr>
<tr>
<td colspan="1" align="center">
<font><h3>Please select the criteria for the report</h3></font>
</td>
</tr>
<tr>
<td align="center" valign="top">
<? // base64_encode(base64_encode('test1'))?>
<br /><br />
<form id='report_form' action="driverreport_sd.php" method="post" name="report_form">
<!--<div class="criteria_div">-->
<table align="center" class="table_border" cellpadding="5" cellspacing="0" width="80%" >


<tr>
<td align="right" class="first_td" >
From Date:
</td>
<td align="left">

<input type="text" class="ctrDateMask ctrDOB" name="From_Date" value="<? if($_POST['pageno']!="" && $_POST['From_Date']!="") { echo date('m-d-Y',strtotime($_POST['From_Date'])); } else echo $_POST['From_Date']; ?>" id="From_Date" maxlength="10" size="10" />
</td>
</tr>
<tr>
<td align="right" class="first_td" >
To Date:
</td>
<td align="left">

<input type="text" class="ctrDateMask ctrDOB" name="To_Date" value="<? if($_POST['pageno']!="" && $_POST['To_Date']!="") { echo date('m-d-Y',strtotime($_POST['To_Date'])); } else echo $_POST['To_Date'];?>" id="To_Date" maxlength="10" size="10" />
</td>
</tr>


<tr>
<td align="right" class="first_td">
Status:
</td>
<td align="left">
<select multiple name='Status' id='Status'>

<?
$statuslist=$ObjReport->ObjStatus->get_Status_List();
while($status=mysql_fetch_object($statuslist))
{
if($status->Status=="Please Select")
{

?><option value="<?=$status->Status?>" <?=($status->Status==$_POST['Status']?"selected=selected":"")?>><?=$status->Status?></option><?
?><option value="ALL" selected="selected" <?=("ALL"==$_POST['Status']?"selected=selected":"")?>>ALL</option><?
}
else
{
?><option value="<?=$status->Status?>" <?=($status->Status==$_POST['Status']?"selected=selected":"")?>><?=$status->Status?></option><?
}
}
?>
</select> </td>
</tr>




<tr>
<td align="right" class="first_td">
School: </td>
<td align="left">
<select name='School' id='School'>
<?
$schoollist=$ObjReport->ObjSchool->get_School_List();
while($school=mysql_fetch_object($schoollist))
{
if($school->School_Name=="Please Select")
{
?><option value="<?=$school->School_Name?>" <?=($school->School_Name==$_POST['School']?"selected=selected":"")?>><?=$school->School_Name?></option><?
?><option value="ALL" selected="selected" <?=("ALL"==$_POST['School']?"selected=selected":"")?>>ALL</option><?

}
else
{
?><option value="<?=$school->School_Name?>" <?=($school->School_Name==$_POST['School']?"selected=selected":"")?>><?=$school->School_Name?></option><?
}
}
?>
</select> </td>
</tr>
<tr>
<td align="right" class="first_td">
Campaign: </td>
<td align="left">
<select name='Campaign' id='Campaign'>
<?
$campaignlist=$ObjReport->ObjCampaign->get_Campaign_List();
while($campaign=mysql_fetch_object($campaignlist))
{
if($campaign->Campaign=="Please Select")
{
?><option value="<?=$campaign->Campaign?>" <?=($campaign->Campaign==$_POST['Campaign']?"selected=selected":"")?>><?=$campaign->Campaign?></option><?
?><option value="ALL" selected="selected" <?=("ALL"==$_POST['Campaign']?"selected=selected":"")?>>ALL</option><?

}
else
{
?><option value="<?=$campaign->Campaign?>" <?=($campaign->Campaign==$_POST['Campaign']?"selected=selected":"")?>><?=$campaign->Campaign?></option><?
}
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" class="first_td">
State: </td>
<td align="left">
<select name='State' id='State'>
<?
$statelist=$ObjReport->ObjState->get_State_List();
while($state=mysql_fetch_object($statelist))
{
if($state->State_Name=="Please Select")
{
?><option value="<?=$state->State_Name?>" <?=($state->State_Name==$_POST['State']?"selected=selected":"")?>><?=$state->State_Name?></option><?
?><option value="ALL" selected="selected" <?=("ALL"==$_POST['State']?"selected=selected":"")?>>ALL</option><?

}
else
{
?><option value="<?=$state->State_Name?>" <?=($state->State_Name==$_POST['State']?"selected=selected":"")?>><?=$state->State_Name?></option><?
}
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" class="first_td">
Student Type: </td>
<td align="left">
<select name='Stdtype' id='Stdtype'>
<?
$stdtypelist=$ObjReport->ObjStdtype->get_stdtype_List();
while($stdtype=mysql_fetch_object($stdtypelist))
{
if($stdtype->Stdtype=="Please Select")
{
?><option value="<?=$stdtype->Stdtype?>" <?=($stdtype->Stdtype==$_POST['Stdtype']?"selected=selected":"")?>><?=$stdtype->Stdtype?></option><?
?><option value="ALL" <?=("ALL"==$_POST['Stdtype']?"selected=selected":"")?>>ALL</option><?

}
else
{
?><option value="<?=$stdtype->Stdtype?>" <?=($stdtype->Stdtype==$_POST['Stdtype']?"selected=selected":"")?> <? if(!isset($_POST['Stdtype']) && $stdtype->Stdtype=="CDR") { echo "Selected=selected"; } ?> ><?=$stdtype->Stdtype?></option><?
}
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" class="first_td">
Primary Address Bad: </td>
<td align="left">
<select name='Primbad' id='Primbad'>
<?
$primbadlist=$ObjReport->ObjPrimbad->get_Primbad_List();
while($primbad=mysql_fetch_object($primbadlist))
{
if($primbad->Primbad_Name=="Please Select")
{
?><option value="<?=$primbad->Primbad_Name?>" <?=($primbad->Primbad_Name==$_POST['Primbad']?"selected=selected":"")?>><?=$primbad->Primbad_Name?></option><?
?><option value="ALL" selected="selected" <?=("ALL"==$_POST['Primbad']?"selected=selected":"")?>>ALL</option><?

}
else
{
?><option value="<?=$primbad->Primbad_Name?>" <?=($primbad->Primbad_Name==$_POST['Primbad']?"selected=selected":"")?><? if(!isset($_POST['Primbad']) && $primbad->Primbad_Name=="No") { echo "Selected=selected"; } ?>><?=$primbad->Primbad_Name?></option><?

}
}
?>
</select> </td>
</tr>

<?
if($_SESSION['user_detail']->Username==11)
{
?>
<tr>
<td align="right" class="first_td">
Radius Rep: </td>
<td align="left">
<select name='Rep' id='Rep'>
<?
$replist=$ObjReport->ObjRep->get_Rep_List();
while($rep=mysql_fetch_object($replist))
{
if($rep->Rep_Name=="11-DavidB")
{
?><option value="11-DavidB" <?=($rep->Rep_Name==11-DavidB?"selected=disabled":"")?>><?=$rep->Rep_Name?></option><?

}
else
{
?><option value="11-DavidB" <?=($rep->Rep_Name==$_POST['11-DavidB']?"selected=disabled":"")?>><?=$rep->Rep_Name?></option><? }
}
?>
</select> </td>
</tr>
<?
}
?>

</tr>

</table>

<table cellpadding="5" cellspacing="0" width="600px" >

<tr>
<td align="center" colspan="2" >
<input type="hidden" id='sort_by' name='sort_by' value="<?=$_POST['sort_by']?>" />
<input type="hidden" name='search_val' id='search_val' value="<?=$_POST['search_val']?>" />
<input type="hidden" name='search_by' id='search_by' value="<?=$_POST['search_by']?>" />
<input type="hidden" name="report_submited" value='report_submited' />
<button type="submit" id="report_submited" name="" value='submit' >Submit</button>
</td>
</tr>
</table>
<!--</div>-->
</form>
</td>


<td align="left">
<!--<div class="chart_close" id='chart_close'>
<img src="../images/btn_close.png" />
</div>-->
<div class="chart_div" id='pie_chart' style="visibility:visible">
</div>
</td>

</tr>
<tr>
<td align="left" >
<?
if($_POST['report_submited'])
{



if($_POST['Status']=="Please Select")
$_POST['Status']="";
/*if($_POST['Status']=="ALL")
$_POST['Status']="";*/

if($_POST['School']=="Please Select")
$_POST['School']="";
/*if($_POST['School']=="ALL")
$_POST['School']="";*/

if($_POST['Campaign']=="Please Select")
$_POST['Campaign']="";
/*if($_POST['Campaign']=="ALL")
$_POST['Campaign']="";*/


if($_POST['State']=="Please Select")
$_POST['State']="";


if($_POST['Stdtype']=="Please Select")
$_POST['Stdtype']="";

if($_POST['Primbad']=="Please Select")
$_POST['Primbad']="";

if($_POST['Rep']=="Please Select")
$_POST['Rep']="";

/*if($_POST['State']=="ALL")
$_POST['State']="";*/
if($_POST['From_Date'] && !isset($_POST['pageno']))
{
$arr_date=explode("-",$_POST['From_Date']);
$_POST['From_Date']=$arr_date[2]."-".$arr_date[0]."-".$arr_date[1];
}

if($_POST['To_Date'] && !isset($_POST['pageno']))
{
$arr_date=explode("-",$_POST['To_Date']);
$_POST['To_Date']=$arr_date[2]."-".$arr_date[0]."-".$arr_date[1];
}
if(!$_POST['sort_by'])
{
$_POST['sort_by']="Status";
}







?>
<br />
<table align="center" class="table_border" cellpadding="5" cellspacing="0" width="600px" >
<tr>
<td align="center" class="first_td" colspan="4">
<b>Summary Report</b>
</td>
</tr>
<tr>
<td class="first_td">
<?
$TotalFiles=$ObjReport->number_of_total_files($_POST['Status'],$_POST['School'],$_POST['Campaign'],$_POST['State'],$_POST['Stdtype'],$_POST['Primbad'],$_POST['Rep'],$_POST['From_Date'],$_POST['To_Date'],$_POST['sort_by'],$_POST['search_by']);

$ReportData=$ObjReport->generate_report_for_csv($_POST['Status'],$_POST['School'],$_POST['Campaign'],$_POST['State'],$_POST['Stdtype'],$_POST['Primbad'],$_POST['Rep'],$_POST['From_Date'],$_POST['To_Date'],$_POST['sort_by'],$_POST['search_by']);
$TotalVisitedFiles=mysql_num_rows($ReportData);
?>
Number of Files: &nbsp;<b><?=$TotalFiles?></b>
</td>



<?

$ReportData=$ObjReport->generate_report_for_csv($_POST['Status'],$_POST['School'],$_POST['Campaign'],$_POST['State'],$_POST['Stdtype'],$_POST['Primbad'],$_POST['Rep'],$_POST['From_Date'],$_POST['To_Date'],$_POST['sort_by'],$_POST['search_by'],$_POST['search_val'],$_POST['search_val']);
$TotalVisitedFiles=mysql_num_rows($ReportData);


$ReportData=$ObjReport->generate_summary_report($_POST['Status'],$_POST['School'],$_POST['Campaign'],$_POST['State'],$_POST['Stdtype'],$_POST['Primbad'],$_POST['Rep'],$_POST['From_Date'],$_POST['To_Date'],$_POST['sort_by'],$_POST['search_by'],$_POST['search_val'],$_POST['search_val']);
$Totalrow=mysql_num_rows($ReportData);
if($Totalrow > 0)
{
?>


<td class="first_td">
Total
</td >
<td class="first_td">
Total % All Files
</td>
<td class="first_td">
Total % Visited Files
</td>
</tr>
<tr>

<td class="first_td">

File Visited (for Given period):
</td>
<td >
<?=$TotalVisitedFiles;?>
<? //$TotalFiles?>
</td>
<td>
<?=number_format((($TotalVisitedFiles*100)/$TotalFiles),1,'.','')?>
<? //number_format((($TotalFiles*100)/$TotalVisitedFiles),1,'.','')?>
</td>
<td>&nbsp;

</td>
</tr>
<?
//$status_list=array('Bad address','Confirmed address','Cured','Pending Cure','Unknown');
$status_detail['Cures']=0;
while($data=mysql_fetch_object($ReportData))
{

//print_r($data);
//echo "<br>";
//if(in_array($data->Status,$status_list))
{
if($data->Status=='Cured' || $data->Status=='Pending Cure')
{
$status_detail['Cures']+=$data->Status_count;
}
else
{
$status_detail[$data->Status]=$data->Status_count;
}
}
}
ksort($status_detail);
foreach($status_detail as $key => $value)
{
if($value!=0)
{
?>
<tr>
<td class="first_td">
<? echo $key; ?>
<?

?>
</td>
<td>
<? echo $value?>

</td>
<td>
<? echo number_format((($value*100)/$TotalFiles),1)?>
<? //echo number_format((($value*100)/$TotalVisitedFiles),1);?>
</td>
<td>
<? echo number_format((($value*100)/$TotalVisitedFiles),1);?>
<? //echo number_format((($value*100)/$TotalFiles),1);?>
</td>
</tr>
<?
}
}
// }
//}

}
?>
</table>
<br /><br />

<?
}
?>
</td>
</tr>
<tr>

<td align="center" colspan="2">
<!--<div id='report_result_div'>
</div>-->
<?
if($_POST['report_submited'])
{





$ReportData=$ObjReport->generate_report($_POST['Status'],$_POST['School'],$_POST['Campaign'],$_POST['State'],$_POST['Stdtype'],$_POST['Primbad'],$_POST['Rep'],$_POST['From_Date'],$_POST['To_Date'],$_POST['sort_by'],$_POST['search_by'],$_POST['search_val']);
$currentTotalRow=mysql_num_rows($ReportData);
if($currentTotalRow>0)
{

?>


<br />
<!--<table class="table_border" cellpadding="5" cellspacing="0" width="2000px">
<tr>
<td width="270px;" align="right">
Seacrh by:

<select name="search_by_option" id='search_by_option'>
<option value="c.cf_644" selected="selected">Student ID</option>
<option value="c.social_security" <?=("c.social_security"==$_POST['search_by']? "selected=selected" : "")?>>Social Security Number</option>
</select>
</td>
<td align="left">
<input type="text" name='search_value' id='search_value' value="<?=$_POST['search_val']?>" />
<button id='search'>Search</button>
</td>
</tr>
</table>-->
<table align="center" class="table_border" cellpadding="5" cellspacing="0" width="1200px" >
<tr>
<td align="center" colspan="19" class="first_td">
<b>Report</b>
</td>
</tr>
<tr>

<td align="center" class="first_td" width="100" >


<?
if($_POST['sort_by']!="Status" && $_POST['sort_by']!='Status DESC')
{
?>
<a class="sort" onclick="" id='Status'>
<!--<img src="../images/up.gif" style="top:-5px; left:15px" />&nbsp;
<img src="../images/down.gif" style=" left:-2px; top:5px" />&nbsp;-->
<u><b>Current Status</b></u>
</a>
<?
}
else if($_POST['sort_by']!="Status")
{
?>
<a class="sort" onclick="" id='Status'>
<img src="../images/down.gif" style="top:0px" />
<u><b>Current Status</b></u>
</a>
<?
}else if($_POST['sort_by']!='Status DESC')
{
?>

<a class="sort" onclick="" id='Status DESC'>
<img src="../images/up.gif" style=" top:-5px" />
<u><b>Current Status</b></u>
</a>
<?
}

?>
</td>


<td align="center" class="first_td" width="90px">



<?
if($_POST['sort_by']!="Status_Date" && $_POST['sort_by']!='Status_Date DESC')
{
?>
<a class="sort" onclick="" id='Status_Date'>
<!--<img src="../images/up.gif" style="top:-5px; left:15px" />&nbsp;
<img src="../images/down.gif" style=" left:-2px; top:5px" />&nbsp;-->
<u><b>Status Date</b></u>
</a>
<?
}
else if($_POST['sort_by']!="Status_Date")
{
?>
<a class="sort" onclick="" id='Status_Date'>
<img src="../images/down.gif" style="top:0px" />&nbsp;

<u><b>Status Date</b></u>
</a>
<?
}else if($_POST['sort_by']!='Status_Date DESC')
{
?>

<a class="sort" onclick="" id='Status_Date DESC'>
<img src="../images/up.gif" style="top:-5px" />&nbsp;
<u><b>Status Date</b></u>
</a>
<?
}

?>

</td>

<td align="center" class="first_td"><b>Campaign</b></td>
<td align="center" class="first_td" width="80">

<b>Student ID</b>

</td>
<td align="center" class="first_td" width="100px">


<?
if($_POST['sort_by']!="Stdtype" && $_POST['sort_by']!='Stdtype DESC')
{
?>
<a class="sort" onclick="" id='Stdtype'>
<!--<img src="../images/up.gif" style="top:-5px; left:15px" />&nbsp;
<img src="../images/down.gif" style=" left:-2px; top:5px" />&nbsp;-->
<u><b>Student Type</b></u>
</a>
<?
}
else if($_POST['sort_by']!="Stdtype")
{
?>
<a class="sort" onclick="" id='Stdtype'>
<img src="../images/down.gif" style="top:0px" />&nbsp;
<u><b>Student Type</b></u>
</a>
<?
}else if($_POST['sort_by']!='Stdtype DESC')
{
?>

<a class="sort" onclick="" id='Stdtype DESC'>
<img src="../images/up.gif" style="top:-5px" />&nbsp;
<u><b>Student Type</b></u>
</a>
<?
}

?>
</td>

<td align="center" class="first_td"><b>Rep</b></td>
<td align="center" class="first_td"><b>First Name</b></td>
<td align="center" class="first_td"><b>Last Name</b></td>
<td align="center" class="first_td"><b>Home Phone</b></td>
<td align="center" class="first_td"><b>Mobile</b></td>
<td align="center" class="first_td"><b>Work Phone</b></td>

<td align="center" class="first_td"><b>Other Phone</b></td>
<!--<td align="center" class="first_td"><b>Street</b></td>
<td align="center" class="first_td"><b>City</b></td>
<td align="center" class="first_td"><b>State</b></td>
<td align="center" class="first_td"><b>Postal Code</b></td>
<td align="center" class="first_td"><b>Social Security Number</b></td>
<td align="center" class="first_td" width="150px"><b>School</b></td>
<td align="center" class="first_td" width="150px"><b>CS Program</b></td>-->



<!--<td align="center" class="first_td">
<?
if($_POST['sort_by']!="Visit_Date" && $_POST['sort_by']!='Visit_Date DESC')
{
?>
<a class="sort" onclick="" id='Visit_Date'>
<img src="../images/up.gif" style="top:-5px" />&nbsp;
<img src="../images/down.gif" style=" left:-17px; top:5px" />&nbsp;
<b>Visiting Date</b>
</a>
<?
}
else if($_POST['sort_by']!="Visit_Date")
{
?>
<a class="sort" onclick="" id='Visit_Date'>
<img src="../images/down.gif" style="top:0px" />&nbsp;

<b>Visiting Date</b>
</a>
<?
}else if($_POST['sort_by']!='Visit_Date DESC')
{
?>

<a class="sort" onclick="" id='Visit_Date DESC'>
<img src="../images/up.gif" style="top:-5px" />&nbsp;
<b>Visiting Date</b>
</a>
<?
}

?>

</td>-->
<td align="center" class="first_td" width="200px"><b>Last Visit Note</b></td>

</tr>
<?
while($data=mysql_fetch_object($ReportData))
{
?>

<tr>
<td>





<?=$data->Status?>&nbsp;
</td>
<td align="center"><?
if(trim($data->Status_Date))
echo date('m-d-Y',strtotime($data->Status_Date));

?>&nbsp;</td>
<td><?=$data->Campaign?>&nbsp;</td>
<td>
<?=$data->Student_ID?>&nbsp;
</td>
<td><?=$data->Stdtype?>&nbsp;</td>
<td><?=$data->Rep?>&nbsp;</td>
<td><?=$data->First_Name?>&nbsp;</td>
<td><?=$data->Last_Name?>&nbsp;</td>
<td><?=$data->Home_Phone?>&nbsp;</td>
<td><?=$data->Mobile?>&nbsp;</td>
<td><?=$data->Work_Phone?>&nbsp;</td>
<td><?=$data->Other_Phone?>&nbsp;</td>
<!--<td><?=$data->Street?>&nbsp;</td>


<td><?=$data->City?>&nbsp;</td>
<td><?=$data->State?>&nbsp;</td>
<td><?=$data->Postal_Code?>&nbsp;</td>
<td><?=$data->SSN?>&nbsp;</td>
<td><?=$data->School?>&nbsp;</td>
<td><?=$data->CS_Program?>&nbsp;</td>-->
<!--<td align="center"><?
if(trim($data->Visit_Date)!="")
{
echo date('m-d-Y',strtotime($data->Visit_Date));
}
?>&nbsp;</td>-->
<td><?

$visit_info_history=explode("\n",$data->visit_info);
echo $visit_info_history[count($visit_info_history)-1];

//echo nl2br($data->visit_info);
?>&nbsp;</td>
</tr>
<?
}
?>
</table>
<table cellpadding="" cellspacing="0" width="600px">
<tr>
<td>
<?=$ObjReport->strPagination?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">

<?
$ReportData=$ObjReport->generate_report_for_csv($_POST['Status'],$_POST['School'],$_POST['Campaign'],$_POST['State'],$_POST['Stdtype'],$_POST['Primbad'],$_POST['Rep'],$_POST['From_Date'],$_POST['To_Date']);
$currentTotalRow=mysql_num_rows($ReportData);
if($currentTotalRow>0)
{
while($data=mysql_fetch_object($ReportData))
{
$chart_data[$data->Status]++;
}
?>
<!-- google pie chart library -->

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['',''],
<? $data_to_chart="";
foreach($chart_data as $key => $value)
{
$data_to_chart.="['".$key."', ".$value."],";
}
echo trim($data_to_chart,","); ?>
]);

var options = {

title: 'Pie Chart for Status',
is3D:true

};




var chart = new google.visualization.PieChart(document.getElementById('pie_chart'));
chart.draw(data, options);
}


/* *********************** */
</script>
<!--<div class="chart_close" id='chart_close'>
<img src="../images/btn_close.png" />
</div>
<div class="chart_div" id='pie_chart'>
</div>-->
<?
}
//print_r($chart_data);
?>
</td>
</tr>
<?
}
else
{
?>
<tr>
<td colspan="2">
<table align="center" class="table_border" cellpadding="5" cellspacing="0" width="600px">
<tr>
<td align="center" class="first_td">
Report
</td>
</tr>
<tr>
<td align="center">
No data found.
</td>
</tr>
</table>
</td>
</tr>
<?
}
}
?>



</table>
<?
}
else
{
if(isset($_SESSION['Login_Person']))
header("location: ./search_student.php");
else
header("location: ../");
}

?>
</body>
</html> 

Basically it is pulling 4 different types of reports from the data and displaying them on the page
Pie chart report
Summary Report
Regular Report
Report that can be exported to csv
Any suggestions? Thanks

I know this doesn’t help to answer your original question, but the way you have your code structured makes it incredibly hard to read (and also maintain).

I’d strongly suggest separating out the different concerns into separate files. You’ve probably heard of the MVC (model-view-controller) pattern, it’s often mentioned in relation to frameworks. It serves as a good rule of thumb for separating out any code.

View - Your HTML should live in it’s own file (with only minimal PHP necessary to output variables and loop over arrays).

Model - The code which deals with getting data to and from the DB should be in it’s own file(s).

Controller - The main PHP file for this page should deal with taking user input (via $_GET, $_POST, or whatever), requesting the relevant data from the model and passing it to the view.

This is somewhat simplified description which glosses over the details, but separating your code along these lines will bring big benefits to you and anyone else who has to work on it.

The ‘From Flat PHP to Symfony’ tutorial does a great job of explaining the process of converting your code this way - you don’t have to go all the way to using Symfony (a framework) to get the benefits of this approach.

1 Like

Hi Fretburner thanks for the advice this is code that was written by a previous programmer so at this point trying to tweak it so it works for the client. I will take a look at the Tutorial. Any suggestions on getting this particular issue fixed I have been bouncing all over the web and not finding a solution yet that works Thanks!

Drummin pointed out two things you need to back in post #5:

Use the array syntax for the select name:

<select multiple name='Status[]' id='Status'>

and change your $ObjReport methods to accept an array rather than a single value.

The other thing you’ll need to do change your validation check. At the moment, you have:

if($_POST['Status']=="Please Select")
        $_POST['Status']="";

but again, this assumes a single value rather than an array, so you’ll need to change it to something like:

if(count($_POST['Status']) == 1 && current($_POST['Status']) == "Please Select")
        $_POST['Status'] = []; // set to empty array to indicate no selection

Also, when you’re building your multiselect lists, you’ll need to change your code slightly to check if the current value is in the array:

<option value="<?=$status->Status?>" <?=(in_array($status->Status, $_POST['Status'])) ? "selected=selected" : "")?> >
        <?=$status->Status?></option>
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.