| Current Path : /var/www/html/mmishra/indem/mailscript/mcell/public_html/query/ |
| Current File : /var/www/html/mmishra/indem/mailscript/mcell/public_html/query/search.php |
<?php
//show page head
include "../page_header.inc";
$db = $_REQUEST["db"];
$submit = $_POST["submit"];
$start_pos = $_REQUEST["start_pos"];
$sfield = $_REQUEST["sfield"];
$svalue = $_REQUEST["svalue"];
$smatch = $_REQUEST["smatch"];
$page_size = $_REQUEST["page_size"];
echo "<input type='hidden' name='db' value='$db'>";
if ($start_pos == "") $start_pos = 0;
if ($page_size == "") $page_size = 20;
switch ($submit){
case "NEXT":
$start_pos = $start_pos + $page_size;
break;
case "PREVIOUS":
$start_pos = $start_pos - $page_size;
break;
default:
$start_pos = 0;
break;
}
//echo "from $start_pos to ($start_pos + $page_size)";
$sql2 = "select description, model_make, unit_price, receive_date, warranty_date, stock_quantity as stock_qty, issued_quantity as issued_qty, scrap_quantity as scrap_qty, remark from $parts_receipt";
//$sql2 = "select found_rows(); mysql_calc_found_rows
$result2 = mysql_query($sql2, $con);
$query_data2 = mysql_fetch_row($result2);
echo "<div align='right'>Search in ";
echo "<select name='sfield'><option value=''>Select column</option>";
foreach($query_data2 as $a => $c){
echo "<option value='" . ucfirst(mysql_field_name($result2, $a)) . "'";
if (ucfirst(mysql_field_name($result2, $a)) == $sfield) echo " selected";
echo ">" . ucfirst(mysql_field_name($result2, $a)) . "</option>";
}
echo "</select> value <input type='text' name='svalue' size='20' value='$svalue'> as ";
echo "<select name='smatch'><option value='1'>Any where</option><option value='2'";
if ($smatch == "2") echo " selected";
echo ">Initial</option><option value='3'";
if ($smatch == "3") echo " selected";
echo ">Exact</option></select> ";
echo "<input type='submit' name='submit' value='SEARCH'></div><br>";
$sql1 = $sql2;
if ($sfield > ""){
$sfield = strtolower($sfield);
if (!strpos($sql1, "where")) $sql1 .= " where";
else $sql1 .= " and";
switch ($smatch){
case "2":
$sql1 .= " $sfield like '$svalue%'";
break;
case "3":
$sql1 .= " $sfield = '$svalue'";
break;
default://case "1":
$sql1 .= " $sfield like '%$svalue%'";
break;
}
$sql1 .= " order by $sfield";
}else{
$sql1 .= " order by category_code, receive_date";
}
$sql1 .= " limit $start_pos, $page_size";
echo "<b>Search Result:</b>";
echo table_data($sql1, $con, $start_pos, $db);
echo "Display <input type='text' name='page_size' value='$page_size' size='2'> records per page ";
echo "<input type='hidden' name='start_pos' value='$start_pos'>";
echo "<input type='submit' name='submit' value='PREVIOUS'> ";
$start_pos += $page_size;
echo "<input type='submit' name='submit' value='NEXT'>";
include "../page_footer.inc";
?>