| Current Path : /var/www/html/mmishra/irp/irp/mcell/search/ |
| Current File : /var/www/html/mmishra/irp/irp/mcell/search/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 "<form method='post' action='/php/mcell/search/search.php'>";
echo "<input type='hidden' name='db' value='$db'>";
if (!$start_pos > 0) $start_pos = 0;
if (!$page_size > 0) $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)";
switch ($db){
case "category_master":
$sql1 = "select * from category_master";
$ttl = "Category";
break;
case "item_master":
$sql1 = "select * from item_master";
$ttl = "Item";
break;
case "supplier_master":
$sql1 = "select * from supplier_master";
$ttl = "Supplier";
break;
case "user_master":
$sql1 = "select * from user_master";
$ttl = "User";
break;
case "job_master":
$sql1 = "select * from job_master";
$ttl = "Job";
break;
default:
$sql1 = "select * from item_master";
$ttl = "Item";
break;
}
$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'>";
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='10' 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 > ""){
if (!strpos($sql1, "where"))
$sql1 = $sql1 . " where";
else
$sql1 = $sql1 . " and";
switch ($smatch){
case "2":
$sql1 = $sql1 . " $sfield like '$svalue%'";
break;
case "3":
$sql1 = $sql1 . " $sfield = '$svalue'";
break;
default://case "1":
$sql1 = $sql1 . " $sfield like '%$svalue%'";
break;
}
$sql2 = $sql1;
$sql1 = $sql1 . " order by $sfield limit $start_pos, $page_size";
}
$result1 = mysql_query($sql1, $link_id);
$result2 = mysql_query($sql2, $link_id);
if(!$result1) error_message(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 head
echo "<table border='0' bgcolor='#abcbca' width='98.5%'>";
echo "<tr><th>No.</th>";
foreach($query_data1 as $a => $c){
echo "<th>" . strtr(strtoupper(mysql_field_name($result1, $a)), "_", " ") . "</th>";
}
echo "</tr>";
$i = $start_pos;
while($query_data1){
$i++;
echo "<tr id='";
if ($i % 2) echo "row1'>";
else echo "row2'>";
echo "<td>$i</td>";
foreach($query_data1 as $col){
echo "<td>$col</td>";
}
echo "</tr>";
$query_data1 = mysql_fetch_row($result1);
}
echo "</table><br>";
echo "<div align='right'>";
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>";
}
?>
</form>
<?php
include "../page_footer.inc";
?>