filter script not working

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 652 Views - Last Post: 04 January 2012 - 07:45 AM Rate Topic: -----

#1 decongh  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 39
  • Joined: 31-December 11

filter script not working

Posted 31 December 2011 - 04:12 AM

Hi there, Am trying to filter results from my db, when i select a value i get no result and no error.I feel its my sql query, this is my code and form.

Or if any one have a simple script that can do the same,i will be grateful, thanks.

<table width="100%" border="0" cellspacing="1" cellpadding="1" align="left">
<tr>
<th scope="col" class="bodytxt" align="left">
<a id="displayText" href="javascript:toggle();">Click To Filter by : [ Vehicle #, Destination and Driver's Name ]</a>
<div id="toggleText" style="display: none">
 
<table width="100%" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<th scope="col" class="bodytxt" width="33%">
<form action=verxbh738hmovx3z.php?nav=view method=post onsubmit='return validate1(this)'>
<table width=100% border=0 cellspacing=1 cellpadding=1>
<tr class='bodytxt'>
 
<td width=25% class="bodytxt">
<label onclick="QA.style.display=QA.style.display=='none'? '' : 'none'">
<input type='radio' name='find' value='date'></label>View Movement Log by Date
<center>
<DIV id=QA style="DISPLAY: none">
Departure Date :<input name="date_out" readonly="Yes" class=textbox><img src=js/cal.gif onclick="displayDatePicker('date_out', this);"><br>
 
Arrival Date :<input name="date_in" readonly="Yes" class=textbox><img src=js/cal.gif onclick="displayDatePicker('date_in', this);">
</center>
</Div> </th>
 
 
<th width="25%" scope="col" class="bodytxt">
<label onclick="QA1.style.display=QA1.style.display=='none'? '' : 'none'">
 
<input type='radio' name='find' value='driver'></label>View Movement Log by Driver's Name</strong>
 
<center>
 
<DIV id=QA1 style="DISPLAY: none" class="bodytxt">Select Name :
 
<select name='driver' class='bodytxt'>
 
<?php $query = "select distinct driver FROM movlog order by driver asc";
 
$result = mysql_query($query);
 
$num_results = mysql_num_rows($result);
 
while ($row = mysql_fetch_array($result))
 
{
$s_country = $row['driver'];
echo"<option>$s_country</option>";
 
}
 
?>
 
</select><br>
 
Arrival Date :<input name="c_startdate" readonly="Yes" class=textbox><img src=js/cal.gif onclick="displayDatePicker('c_startdate', this);"><br>
 
Departure Date :<input name="c_enddate" readonly="Yes" class='textbox'><img src=js/cal.gif onclick="displayDatePicker('c_enddate', this);">
</Div>
</center> </th>
<th width="25%" scope="col" class="bodytxt">
 
<label onclick="QA2.style.display=QA2.style.display=='none'? '' : 'none'">
 
<input type=radio name='find' value='vreg'></label>View Movement Log by Vehicle # </strong>
 
<DIV id=QA2 style="DISPLAY: none" class="bodytxt">Vehicle # :
<br>
 
<?php
 
$query = "select distinct vreg FROM movlog";
$movlog_result= mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$movlog_num = 0;
$movlog_num = mysql_numrows($movlog_result);
$i = 0;
$x = 0;
 
while($i < $movlog_num)
{
$id = mysql_result($movlog_result,$i,"vreg");
$x = $x + 1;
$i++;
}
?>
 
<script language="javascript">
 
 
locations_text = new Array(<?=$x?>);
 
locations_text [0] = new Array(1)
 
//arrays for the text
 
<?
 
$movlog_num = $x+1;
 
$n = 1;
 
while($n < $movlog_num)
 
{
echo"locations_text [$n] = new Array(1);";
 
$n++;
 
}
 
?>
 
//arrays for values
 
locations_values = new Array(<?=$x?>);
locations_values [0] = new Array(1)
<?
 
$movlog = $x+1;
$m = 1;
while($m < $movlog)
{
echo"locations_values [$m] = new Array(1);";
$m++;
}
 
$queryfnum = "select distinct vreg FROM movlog order by vreg";
$movlog_result4= mysql_query($queryfnum) or trigger_error("SQL", E_USER_ERROR);
$movlog_num4 = 0;
$movlog_num4 = mysql_numrows($movlog_result4);
$i = 0;
$z = 1;
$today_date = date("y-m-d");
 
while($i < $movlog_num4)
{
$vreg = mysql_result($movlog_result4,$i,"vreg");
 
$query1 = "select id,vreg,desti FROM movlog where vreg='$vreg' order by desti";
$result1 = mysql_query($query1);
$y = 0;
$num_results = mysql_num_rows($result1);
while ($row = mysql_fetch_array($result1))
{
$fid = $row['id'];
$id = $row['origin'];
$vreg = $row['vreg'];
$desti = $row['desti'];
 
list($dy, $dm, $dd) = split('[/.-]', $dept);
$query2 = "select * from movlog where id='$id'";
$result2 = mysql_query($query2);
$num_results = mysql_num_rows($result2);
while ($row = mysql_fetch_array($result2))
{
$town = $row['desti'];
$chkorigin = $town;
}
 
$query3 = "select * FROM movlog where desti='$desti'";
$result3 = mysql_query($query3);
$num_results = mysql_num_rows($result3);
while ($row = mysql_fetch_array($result3))
{
$town = $row['desti'];
$chkdestination = $town;
}
echo "locations_text [$z][$y] = '$vreg » $chkorigin - $chkdestination » $dd-$dm-$dy';";
echo "locations_values [$z][$y] = '$fid';";
$y = $y + 1;
}
$z = $z + 1;
$i++;
}
?>
 
//============================================
//function to write the locations
 
function writeLocations11(theObject)
{
theForm = theObject.form;
var regionnum=theForm.region11.selectedIndex;
 
theForm.vreg.selectedIndex = 0;
 
for ( x=0;x<locations_text[regionnum].length;x++)
 
{
theForm.vreg.options[x] = new Option(locations_text[regionnum][x], locations_values[regionnum][x]);
}
 
theForm.vreg.length = x;
theForm.vreg.focus();
 
}
 
//-->
</script>
<select class=textbox name="region11" onchange="Javascript:writeLocations11(this);">
<option value="null">--select--</option>
<?php
$query = "select id,vreg FROM movlog order by vreg";
$movlog_result= mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$movlog_num = 0;
$movlog_num = mysql_numrows($movlog_result);
 
$i = 0;
$x = 0;
$tempvreg = "";
while($i < $movlog_num)
{
$vreg = mysql_result($movlog_result,$i,"vreg");
$fid = mysql_result($movlog_result,$i,"id");
if($vreg != $tempvreg)
{
echo"<option value='$fid'>$vreg</option>";
$tempvreg = $vreg;
}
$i++;
}
?>
</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
Vehicles Available <font color=red>*</font>
<select name="vreg" class=textbox>
<option value="null">--select--</option>
</select>
</Div>
</center>
</th>
<th width="25%" scope="col" class="bodytxt">
<label onclick="QA3.style.display=QA3.style.display=='none'? '' : 'none'">
<input type='radio' name='find' value='desti'>
</label>View Movement Log by Destination</strong>
<center>
<DIV id=QA3 style="DISPLAY: none" class="bodytxt">Select Destination :
<select name='desti' class='bodytxt'>
<?php $query = "select distinct desti FROM movlog order by desti asc";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
while ($row = mysql_fetch_array($result))
 
{
$s_country = $row['desti'];
echo"<option>$s_country</option>";
}
?>
</select><br>
 
Arrival Date :<input name="cstartdate" readonly="Yes" class=textbox><img src=js/cal.gif onclick="displayDatePicker('cstartdate', this);"><br>
 
Departure Date :<input name="cenddate" readonly="Yes" class='textbox'><img src=js/cal.gif onclick="displayDatePicker('cenddate', this);">
</Div>
</center> </th>
</tr>
</table>
<?php echo"
 
<table width='100%' border='0' cellspacing='1' cellpadding='1' align='center'>
 
<tr>
<td colspan=8><div align=center><hr /></div></td>
</tr>
<tr align=center><br><br>
<td colspan=5><br><br><input name=Submit type=submit class=bottom value=Submit>
<input name=Reset type=reset class=bottom value=Reset>
 
</td>
</tr>
</table>
</form>";?>
</form>
</th>
</tr>
</table>
 
</div>
</td>
</th>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<th scope="col">
<?php
$date = "";
$driver = "";
$vreg = "";
$desti = "";
 
$radiotype = $_REQUEST['find'];
 
if ($radiotype == "")
{
echo"<p class='bodytxt'>N.B: You can filter by selecting any of the category of movement log you want to view.</p><br><br>
";
exit;
}
 
if ($radiotype == "date")
{
 
 
echo
 
"
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle #</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage Out</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage In</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Filled [Ltrs]</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Driver</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Cost (Gh ¢)</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle Type</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>View Details</font></th>
</tr>
</table>
 
";
 
 
{
 
 
$query = "select * FROM movlog order by id desc";
$pager = new PS_Pagination($conn,$query,10,10);
$accra = $pager->paginate();
while($row = mysql_fetch_assoc($accra))
{
$id = $row['id'];
 
$date_out = $_REQUEST['date_out'];
$date_in = $_REQUEST['date_in'];
list($d, $m, $y) = split('[/.-]', $date_out);
list($ed, $em, $ey) = split('[/.-]', $date_in);
$date_out = $y."-".$m."-".$d;
$date_in = $ey."-".$em."-".$ed;
 
$mileage_out = $row['mileage_out'];
$mileage_in = $row['mileage_in'];
$vreg = $row['vreg'];
$ftype = $row['ftype'];
$famount = $row['famount'];
$driver = $row['driver'];
$vtype = $row['vtype'];
$dept = $row['dept'];
$date_out = $row['date_out'];
$date_in = $row['date_in'];
$time_out = $row['time_out'];
$time_in = $row['time_in'];
$tt_con = $row['tt_con'];
$tf_con = $row['tf_con'];
}
 
echo
"
 
<table width='100%' align='center' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_out</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_in</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$famount</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vtype</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'>
<a href='verxbh738hmovx3z.php?nav=view&id=$id&zy9stxyw...' target='_blank'><img src='icon/view.gif' border='0'></a></td>
</tr>
</table>
 
 
";
 
}
}
 
 
if ($radiotype == "driver")
{
 
echo
 
"
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle #</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage Out</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage In</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Filled [Ltrs]</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Driver</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Cost (Gh ¢)</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle Type</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>View Details</font></th>
</tr>
</table>
 
";
 
 
{
//$query = "SELECT * FROM movlog where driver='$driver' dates BETWEEN '$date_out' and '$date_in'";
$query= "SELECT * FROM movlog WHERE driver ='$driver' AND '$date_out' >= '$date_out' AND '$date_in' <= '$date_in'";
$pager = new PS_Pagination($conn,$query,10,10);
$accra = $pager->paginate();
while($row = mysql_fetch_assoc($accra))
{
$id = $row['id'];
$date_out = $_REQUEST['c_startdate'];
$date_in = $_REQUEST['c_enddate'];
list($d, $m, $y) = split('[/.-]', $date_out);
list($ed, $em, $ey) = split('[/.-]', $date_in);
$date_out = $y."-".$m."-".$d;
$date_in = $ey."-".$em."-".$ed;
 
$mileage_out = $row['mileage_out'];
$mileage_in = $row['mileage_in'];
$vreg = $row['vreg'];
$ftype = $row['ftype'];
$famount = $row['famount'];
$driver = $row['driver'];
$vtype = $row['vtype'];
$dept = $row['dept'];
$date_out = $row['date_out'];
$date_in = $row['date_in'];
$time_out = $row['time_out'];
$time_in = $row['time_in'];
$tt_con = $row['tt_con'];
$tf_con = $row['tf_con'];
 
 
 
}
 
 
 
echo
"
 
<table width='100%' align='center' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_out</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_in</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$famount</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vtype</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'>
<a href='verxbh738hmovx3z.php?nav=view&id=$id&zy9stxyw...' target='_blank'><img src='icon/view.gif' border='0'></a></td>
</tr>
</table>
 
 
";
 
}
}
 
 
 
if ($radiotype == "vreg")
{
 
echo
 
"
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle #</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage Out</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage In</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Filled [Ltrs]</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Driver</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Cost (Gh ¢)</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle Type</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>View Details</font></th>
</tr>
</table>
 
";
 
 
{
$query= "SELECT * FROM movlog WHERE vreg ='$vreg' order by driver desc";
$pager = new PS_Pagination($conn,$query,10,10);
$accra = $pager->paginate();
while($row = mysql_fetch_assoc($accra))
{
$id = $row['id'];
$mileage_out = $row['mileage_out'];
$mileage_in = $row['mileage_in'];
$vreg = $row['vreg'];
$ftype = $row['ftype'];
$famount = $row['famount'];
$driver = $row['driver'];
$vtype = $row['vtype'];
$dept = $row['dept'];
$date_out = $row['date_out'];
$date_in = $row['date_in'];
$time_out = $row['time_out'];
$time_in = $row['time_in'];
$tt_con = $row['tt_con'];
$tf_con = $row['tf_con'];
 
 
 
}
 
 
 
echo
"
 
<table width='100%' align='center' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_out</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_in</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$famount</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vtype</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'>
<a href='verxbh738hmovx3z.php?nav=view&id=$id&zy9stxyw...' target='_blank'><img src='icon/view.gif' border='0'></a></td>
</tr>
</table>
 
 
";
 
}
}
 
 
if ($radiotype == "desti")
{
 
echo
 
"
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle ##</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage Out</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Mileage In</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Filled [Ltrs]</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Driver</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Fuel Cost (Gh ¢)</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>Vehicle Type</font></th>
<th width='12.5' align='center' class='bodytxt' bgcolor='#330066'><font color='#ffffff'>View Details</font></th>
</tr>
</table>
 
";
 
 
{
$query= "SELECT * FROM movlog WHERE desti ='$desti' BETWEEN '$date_out' AND '$date_in' order by desti desc";
$pager = new PS_Pagination($conn,$query,10,10);
$accra = $pager->paginate();
while($row = mysql_fetch_assoc($accra))
{
$id = $row['id'];
 
$date_out = $_REQUEST['cstartdate'];
$date_in = $_REQUEST['cenddate'];
list($d, $m, $y) = split('[/.-]', $date_out);
list($ed, $em, $ey) = split('[/.-]', $date_in);
$date_out = $y."-".$m."-".$d;
$date_in = $ey."-".$em."-".$ed;
 
$mileage_out = $row['mileage_out'];
$mileage_in = $row['mileage_in'];
$vreg = $row['vreg'];
$ftype = $row['ftype'];
$famount = $row['famount'];
$driver = $row['driver'];
$vtype = $row['vtype'];
$dept = $row['dept'];
$date_out = $row['date_out'];
$date_in = $row['date_in'];
$time_out = $row['time_out'];
$time_in = $row['time_in'];
$tt_con = $row['tt_con'];
$tf_con = $row['tf_con'];
}
 
echo
"
 
<table width='100%' align='center' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_out</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_in</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$famount</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vtype</font></td>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'>
<a href='verxbh738hmovx3z.php?nav=view&id=$id&zy9stxyw...' target='_blank'><img src='icon/view.gif' border='0'></a></td>
</tr>
</table>
 
 
";
 
}
}
 
 
//Display the full navigation in one go
echo"<table width=100% border=0 cellspacing=4 cellpadding=1 bgcolor='#D6D6D6' class='bodyTxt'>
<tr><td colspan=14 align=center ><br>" .$pager->renderFullNav(). "</td></tr></table>";
?>
 
</th>
</tr>
</table>


Is This A Good Question/Topic? 0
  • +

Replies To: filter script not working

#2 Slice  Icon User is offline

  • D.I.C Addict


Reputation: 196
  • View blog
  • Posts: 591
  • Joined: 24-November 08

Re: filter script not working

Posted 31 December 2011 - 04:39 AM

Can you not just post where you think the problem might be occurring? You say in your query, but a quick scroll through showed me at least 10+ queries.

I can't see anyone on here shuffling through 620 lines of unindented code looking for a problem.
Was This Post Helpful? 3
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3039
  • View blog
  • Posts: 4,554
  • Joined: 08-June 10

Re: filter script not working

Posted 31 December 2011 - 04:46 AM

View PostSlice, on 31 December 2011 - 11:39 AM, said:

I can't see anyone on here shuffling through 620 lines of unindented code looking for a problem.

Exactly. Although the HTML/CSS/JS/PHP infusion is even more of an obstacle.

Look into Code Separation!

Also, make sure that the return value of EVERY SINGLE mysql_query call is tested before it is used. Otherwise you won't see any errors even if they occur.
Was This Post Helpful? 3
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2485
  • View blog
  • Posts: 8,521
  • Joined: 08-August 08

Re: filter script not working

Posted 31 December 2011 - 09:30 AM

View PostAtli, on 31 December 2011 - 07:46 AM, said:

Although the HTML/CSS/JS/PHP infusion is even more of an obstacle.

Technically, the OP isn't using CSS. Of course, using style tags in the HTML makes it even harder to read.

@decongh,
  • Holy mixed languages, batman!
  • You should be using prepared statements. Read up on PDO or MySQLi.

Was This Post Helpful? 0
  • +
  • -

#5 decongh  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 39
  • Joined: 31-December 11

Re: filter script not working

Posted 31 December 2011 - 11:41 AM

the is the php script doing the filtering:


<?php
 
$date = "";
$driver = "";
$vreg = "";
$desti = "";
 
$radiotype = $_REQUEST['find'];
 
if ($radiotype == "")
{
echo"<p class='bodytxt'>N.B: You can filter by selecting any of the category of movement log you want to view.</p><br><br>
";
exit;
}
if($radiotype == "date")
{
$date_out = $_REQUEST['date_out'];
$date_in = $_REQUEST['date_in'];
list($d, $m, $y) = split('[/.-]', $date_out);
list($ed, $em, $ey) = split('[/.-]', $date_in);
$date_out = $y."-".$m."-".$d;
$date_in = $ey."-".$em."-".$ed;
}
elseif ($radiotype == "driver")
{
$desti = $_REQUEST['desti'];
$date_out = $_REQUEST['c_startdate'];
$date_in = $_REQUEST['c_enddate'];
list($d, $m, $y) = split('[/.-]', $date_out);
list($ed, $em, $ey) = split('[/.-]', $date_in);
$date_out = $y."-".$m."-".$d;
$date_in = $ey."-".$em."-".$ed;
}
 
elseif ($radiotype == "vreg")
{
{
$vreg = $_REQUEST['vreg'];
}
$movlog_num = 0;
$movlog_result = mysql_QUERY("select * FROM movlog order by cur_date asc");
$i = 0;
 
}
 
elseif ($radiotype == "desti")
{
$date_out = $_REQUEST['cstartdate'];
$date_in = $_REQUEST['cenddate'];
list($d, $m, $y) = split('[/.-]', $date_out);
list($ed, $em, $ey) = split('[/.-]', $date_in);
$date_out = $y."-".$m."-".$d;
$date_in = $ey."-".$em."-".$ed;
}
 
echo "<center>
<p><br><strong>Sales</strong></p>
<table width=100% border=0 cellspacing=3 cellpadding=0>";
 
if($radiotype == "date")
 
{
$query = "SELECT * FROM movlog where between '$date_in' and '$date_out'";
}
 
elseif ($radiotype == "desti")
 
{
$query = "SELECT * FROM movlog where desti='$desti' between '$date_out' and '$date_in'";
}
 
elseif ($radiotype == "driver")
 
{
$query = "SELECT * FROM movlog where driver='$driver' between '$date_out' and '$date_in'";
}
 
elseif ($radiotype == "vreg")
{
$totalquery = "SELECT * FROM movlog where vreg='$vreg'";
$date_out = "";
$date_in = "";
}
 
$query_result= mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_result_num = 0;
$query_result_num = mysql_numrows($query_result);
$i = 0;
 
while($i < $query_result_num)
{
$query_result = mysql_result($query_result,$i);
$i++;
}
 
echo
"
 
<table width='100%' align='center' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
 
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_out</font></td>
 
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_in</font></td>
 
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$famount</font></td>
 
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>
 
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
 
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vtype</font></td>
 
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'>
<a href='verxbh738hmovx3z.php?nav=view&id=$id&zy9stxyw...' target='_blank'><img src='icon/view.gif' border='0'></a></td>
</tr>
</table>
 
";
?>

This post has been edited by CTphpnwb: 31 December 2011 - 11:44 AM
Reason for edit:: Added code tags!

Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2485
  • View blog
  • Posts: 8,521
  • Joined: 08-August 08

Re: filter script not working

Posted 31 December 2011 - 11:47 AM

Your code is still unindented.
If you make it easy to give you help then you'll get more of it.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,511
  • Joined: 23-August 08

Re: filter script not working

Posted 31 December 2011 - 02:05 PM

Here, I'll help you out with the indentation:

<?php

$date = "";
$driver = "";
$vreg = "";
$desti = "";

$radiotype = $_REQUEST['find'];

if ($radiotype == "")
{
	echo"<p class='bodytxt'>N.B: You can filter by selecting any of the category of movement log you want to view.</p><br><br>
				";
	exit;
}
if($radiotype == "date")
{
	$date_out = $_REQUEST['date_out'];
	$date_in = $_REQUEST['date_in'];
	list($d, $m, $y) = split('[/.-]', $date_out);
	list($ed, $em, $ey) = split('[/.-]', $date_in);
	$date_out = $y."-".$m."-".$d;
	$date_in = $ey."-".$em."-".$ed;
}
elseif ($radiotype == "driver")
{
	$desti = $_REQUEST['desti'];
	$date_out = $_REQUEST['c_startdate'];
	$date_in = $_REQUEST['c_enddate'];
	list($d, $m, $y) = split('[/.-]', $date_out);
	list($ed, $em, $ey) = split('[/.-]', $date_in);
	$date_out = $y."-".$m."-".$d;
	$date_in = $ey."-".$em."-".$ed;
}

elseif ($radiotype == "vreg")
{
	{
		$vreg = $_REQUEST['vreg'];
	}
	$movlog_num = 0;
	$movlog_result = mysql_QUERY("select * FROM movlog order by cur_date asc");
	$i = 0;

}

elseif ($radiotype == "desti")
{
	$date_out = $_REQUEST['cstartdate'];
	$date_in = $_REQUEST['cenddate'];
	list($d, $m, $y) = split('[/.-]', $date_out);
	list($ed, $em, $ey) = split('[/.-]', $date_in);
	$date_out = $y."-".$m."-".$d;
	$date_in = $ey."-".$em."-".$ed;
}

echo "<center>
<p><br><strong>Sales</strong></p>
<table width=100% border=0 cellspacing=3 cellpadding=0>";

if($radiotype == "date")
{
	$query = "SELECT * FROM movlog where between '$date_in' and '$date_out'";
}
elseif ($radiotype == "desti")
{
	$query = "SELECT * FROM movlog where desti='$desti' between '$date_out' and '$date_in'";
}
elseif ($radiotype == "driver")
{
	$query = "SELECT * FROM movlog where driver='$driver' between '$date_out' and '$date_in'";
}
elseif ($radiotype == "vreg")
{
	$totalquery = "SELECT * FROM movlog where vreg='$vreg'";
	$date_out = "";
	$date_in = "";
}

$query_result= mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_result_num = 0;
$query_result_num = mysql_numrows($query_result);
$i = 0;

while($i < $query_result_num)
{
	$query_result = mysql_result($query_result,$i);
	$i++;
}

echo
"

<table width='100%' align='center' border='0' cellspacing='1' cellpadding='1'>
<tr>
<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>

<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_out</font></td>

<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$mileage_in</font></td>

<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$famount</font></td>

<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>

<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>

<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vtype</font></td>

<td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'>
<a href='verxbh738hmovx3z.php?nav=view&id=$id&zy9stxyw...' target='_blank'><img src='icon/view.gif' border='0'></a></td>
</tr>
</table>

";
?>


Was This Post Helpful? 2
  • +
  • -

#8 decongh  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 39
  • Joined: 31-December 11

Re: filter script not working

Posted 02 January 2012 - 04:41 AM

am trying to create a filter,but am geting no result with this,my data type in mysql is date.Any help pls?

    <?php
     
    $date = "";
    $driver = "";
    $vreg = "";
    $desti = "";
     
    $radiotype = $_REQUEST['find'];
     
    if ($radiotype == "")
    {
    echo"<p class='bodytxt'>N.B: You can filter by selecting any of the movement log you want to view.</p><br><br>
    ";
    exit();
    }
    if($radiotype == "driver")
     
    {
     
    $date_out = "";
    $date_in = "";
    $date_out = $_REQUEST['date_out'];
    $date_in = $_REQUEST['date_in'];
    list($d, $m, $y) = split('[/.-]', $date_out);
    list($ed, $em, $ey) = split('[/.-]', $date_in);
    $date_out = $y."-".$m."-".$d;
    $date_in = $ey."-".$em."-".$ed;
     
    $query = "SELECT * FROM movlog WHERE driver='$driver' BETWEEN ('$date_out') AND ('$date_in')";
     
     
    $pager = new PS_Pagination($conn,$query,10,10);
    $accra = $pager->paginate();
    while($row = mysql_fetch_assoc($accra))
     
     
     
    $id = $row['id'];
    $mileage_out = $row['mileage_out'];
    $mileage_in = $row['mileage_in'];
    $vreg = $row['vreg'];
    $ftype = $row['ftype'];
    $famount = $row['famount'];
    $driver = $row['driver'];
    $vtype = $row['vtype'];
    $dept = $row['dept'];
    $date_out = $row['date_out'];
    $date_in = $row['date_in'];
    $time_out = $row['time_out'];
    $time_in = $row['time_in'];
    $tt_con = $row['tt_con'];
    $tf_con = $row['tf_con'];
     
    }
     
    echo
    "
     
    <table width='100%' align='center' border='0' cellspacing='1' cellpadding='1'>
    <tr>
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
     
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$date_out</font></td>
     
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$date_in</font></td>
     
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$famount</font></td>
     
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>
     
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$vreg</font></td>
     
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'><font color='#ffffff'>$driver</font></td>
     
    <td width='12.5' align='center' valign='middle' bgcolor='#009933' class='bodytxt'>
    <a href='trim.php?nav=view&id=$id&zy9stxyw...' target='_blank'><img src='icon/view.gif' border='0'></a></td>
    </tr>
    </table>
     
    ";
     
    ?>

Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3039
  • View blog
  • Posts: 4,554
  • Joined: 08-June 10

Re: filter script not working

Posted 02 January 2012 - 05:37 AM

Hey.

Here are a few things to consider:

  • You should enable error_reporting in your config to see any error messages your script is emitting. You can also just put this at the top of the page.
    ini_set("display_errors", true);
    error_reporting(E_ALL);
    
    


  • Don't use $_REQUEST. Instead, use the super-global appropriate for the protocol you are trying to use: $_GET, $_POST or $_COOKIE. - If you use $_REQUEST you can't be sure where the data is coming from. For example, if both $_COOKIE['value'] and $_POST['value'] are set, the COOKIE will override POST.

  • Your $driver variable is never set to any value before you use it in your SQL query, so the WHERE clause will always read as:
    ... WHERE driver='' ...
    


  • The data used in your last echo is only set if the $radiotype is "driver", but the echo is outside that IF statement. Meaning that if the value is not "driver", none of the data will be set but the echo will still happen. - You should put the echo inside the IF statement and put an alternative echo in an ELSE statement.

  • Use ELSE IF clauses.
    // Don't do this.
    if ($value == 1) {
        echo "It's 1.";
    }
    if ($value == 2) {
        echo "It's 2.";
    }
    
    // Do this:
    if ($value == 1) {
        echo "It's 1.";
    }
    else if ($value == 2) {
        echo "It's 2.";
    }
    else {
        echo "It's not 1 or 2.";
    }
    
    


  • This whole section:
    $date_out = $_REQUEST['date_out'];
    $date_in = $_REQUEST['date_in'];
    list($d, $m, $y) = split('[/.-]', $date_out);
    list($ed, $em, $ey) = split('[/.-]', $date_in);
    $date_out = $y . "-" . $m . "-" . $d;
    $date_in = $ey . "-" . $em . "-" . $ed;
    
    

    This could be done using the strtotime and date functions.
    $my_date = date('Y-m-d', strtotime($_POST['my_date']));
    if (!$my_date) {
        trigger_error("The date could not be parsed!", E_USER_WARNING);
    }
    
    

Was This Post Helpful? 4
  • +
  • -

#10 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3039
  • View blog
  • Posts: 4,554
  • Joined: 08-June 10

Re: filter script not working

Posted 02 January 2012 - 05:47 AM

** Threads merged. **

Do not double post your questions!
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2485
  • View blog
  • Posts: 8,521
  • Joined: 08-August 08

Re: filter script not working

Posted 02 January 2012 - 08:14 AM

View PostAtli, on 02 January 2012 - 08:37 AM, said:

Hey.

Here are a few things to consider:

[*]Use ELSE IF clauses.
// Don't do this.
if ($value == 1) {
    echo "It's 1.";
}
if ($value == 2) {
    echo "It's 2.";
}

// Do this:
if ($value == 1) {
    echo "It's 1.";
}
else if ($value == 2) {
    echo "It's 2.";
}
else {
    echo "It's not 1 or 2.";
}


When you have a series of if...else statements that are only testing one variable it's better to use a switch:
switch($value)
  case 1:
   echo "It's 1.";
   break;
  case 2:
   echo "It's 2.";
   break;
  case 3:
   echo "It's 3.";
   break;
  default:
   echo "it's not 1, 2, or 3.";
   break;
}

Was This Post Helpful? 0
  • +
  • -

#12 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3039
  • View blog
  • Posts: 4,554
  • Joined: 08-June 10

Re: filter script not working

Posted 03 January 2012 - 07:54 AM

View PostCTphpnwb, on 02 January 2012 - 03:14 PM, said:

When you have a series of if...else statements that are only testing one variable it's better to use a switch:

That's highly subjective. At least when used like you did in your example. - The only benefit of using switch statement is the ability to have one case drop into another. If you don't need that, all that remains is the syntax.

Personally I avoid switch statements when there is no clear advantage. They remind me to much of goto statements :)
Was This Post Helpful? 1
  • +
  • -

#13 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: filter script not working

Posted 03 January 2012 - 08:50 AM

Hi,

$query = "SELECT * FROM movlog WHERE driver='$driver' BETWEEN ('$date_out') AND ('$date_in')";



I believe this could be part of your problem. Unless * returns a value that can be between $date_out and $date_in you will not get an error but will not get any results either. Since I don't know your schema I can't say for certain what you need to change but it most likely is meant to be something like :
$query = "SELECT * FROM movlog WHERE driver='$driver' AND some_date_field BETWEEN ('$date_out') AND ('$date_in')";


Was This Post Helpful? 2
  • +
  • -

#14 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2485
  • View blog
  • Posts: 8,521
  • Joined: 08-August 08

Re: filter script not working

Posted 03 January 2012 - 09:08 AM

View PostAtli, on 03 January 2012 - 10:54 AM, said:

View PostCTphpnwb, on 02 January 2012 - 03:14 PM, said:

When you have a series of if...else statements that are only testing one variable it's better to use a switch:

That's highly subjective. At least when used like you did in your example. - The only benefit of using switch statement is the ability to have one case drop into another. If you don't need that, all that remains is the syntax.

Personally I avoid switch statements when there is no clear advantage. They remind me to much of goto statements :)

I suppose it is somewhat subjective, but I think there is a clear advantage when you're just testing one variable and you have more than one else. It's more readable, since a switch is basically a simplified version of if...elseif...elseif...
Was This Post Helpful? 1
  • +
  • -

#15 decongh  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 39
  • Joined: 31-December 11

Re: filter script not working

Posted 04 January 2012 - 06:49 AM

View PostAtli, on 02 January 2012 - 05:47 AM, said:

** Threads merged. **

Do not double post your questions!


Am sorry for doing that again, am new around and thought i got no replay to my post.

Thanks to all those who have replayed to my post,am so amazed.Thanks for the vast display of programming knowledge
, am very grateful.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2