| Current Path : /var/www/html/mmishra/irp/irp/pcstore/ |
| Current File : /var/www/html/mmishra/irp/irp/pcstore/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)";
$sql1 = "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 item_master";
//$sql1 = "select * from item_master";
$ttl = "Item";
$sql2 = $sql1;
//$sql2 = "select found_rows(); mysql_calc_found_rows
$result2 = mysql_query($sql2, $link_id);
$query_data2 = mysql_fetch_row($result2);
echo "<div align='right'><b>$ttl</b> 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>";
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;
}
$sql2 = $sql1;
$sql1 .= " order by $sfield";
}else{
$sql1 .= " order by category_code, receive_date";
}
$sql1 .= " limit $start_pos, $page_size";
$result1 = mysql_query($sql1, $link_id);
$result2 = mysql_query($sql2, $link_id);
if(!$result1) echo sql_error();
$query_data1 = mysql_fetch_row($result1);
$query_data2 = mysql_fetch_row($result2);
echo "<b>Search Result:</b> (";
$total_records = mysql_num_rows($result2);
if (!$total_records)
echo "No $ttl found)<p>";
else{
echo $total_records . " $ttl found)";
//show table data
echo table_data($sql1, $link_id, $start_pos, $db);
echo "<div align='right'>Click on column heading to sort result on that column values. ";
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'>";
if ($start_pos >= $page_size){
echo "<input type='submit' name='submit' value='PREVIOUS'> ";
}
$start_pos = $start_pos + $page_size;
if ($start_pos < $total_records) echo "<input type='submit' name='submit' value='NEXT'>";
echo "</div>";
}
include "page_footer.inc";
?>