| Current Path : /var/www/html/mmishra/mm/libsite/ |
| Current File : /var/www/html/mmishra/mm/libsite/new.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"];
$refine = $_REQUEST["refine"];
$sql9 = $_REQUEST["sql9"];
$match_array = array("any where", "initial", "exact");
$refine_array = array('all', 'result');
$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)";
switch ($db){
case "new_book":
$sql1 = "select a.accession_no, a.document_code, b.title, b.author, a.receive_date from accession_master a, book_master b where a.document_code=b.document_code and month(a.receive_date) = month(curdate())";
$ttl = "New Books";
break;
case "new_journal":
$sql1 = "select a.accession_no, a.document_code, j.title, j.author from accession_master a, journal_master j where a.document_code=j.document_code and month(a.receive_date)=month(curdate())";
$ttl = "New Journals";
break;
case "new_electronic":
$sql1 = "select a.accession_no, a.document_code, j.title, j.author from accession_master a, journal_master j where a.document_code=j.document_code and month(a.receive_date)=month(curdate())";
$ttl = "New Electronic Documents";
break;
case "new_member":
$sql1 = "select member_code, name, email, category_code from member_master month(joining_date)=month(curdate())";
$ttl = "New Member";
break;
default:
$sql1 = "select a.accession_no, a.document_code, b.title, b.author, a.receive_date from accession_master a, book_master b where a.document_code = b.document_code and month(a.receive_date) = month(curdate())";
$ttl = "New Books";
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'><u><b>$ttl</b></u> search ";
echo "<input type='text' name='svalue' size='15' value='$svalue'> ";
echo "in <select name='sfield'><option value=''>Select column</option>";
foreach($query_data2 as $i => $a){
echo "<option value='" . ucfirst(mysql_field_name($result2, $i)) . "'";
if (ucfirst(mysql_field_name($result2, $i)) == $sfield) echo " selected";
echo ">" . ucfirst(mysql_field_name($result2, $i)) . "</option>";
}
echo "</select> as ";
echo "<select name='smatch'>";
foreach ($match_array as $i => $a){
echo "<option value='$i'";
if ($smatch == $i) echo " selected";
echo ">$a</option>";
}
echo "</select> from ";
echo "<select name='refine'>";
foreach ($refine_array as $i => $a){
echo "<option value='$i'";
if ($refine == $i) echo " selected";
echo ">$a</option>";
}
echo "</select> ";
echo "<input type='submit' name='submit' value='SEARCH'></div><br>";
if ($refine == 1) $sql1 = $sql9;
//echo $sql1;
if ($sfield <> ""){
if (!strpos($sql1, "where"))
$sql1 .= " where";
else
$sql1 .= " and";
switch ($smatch){
case "1":
$sql1 .= " $sfield like '$svalue%'";
break;
case "2":
$sql1 .= " $sfield = '$svalue'";
break;
default://case "1"
$sql1 .= " $sfield like '%$svalue%'";
break;
}
$sql2 = $sql1;
$sql9 = $sql1;//to pass on to next page
$sql1 .= " order by $sfield";
}
$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 "<input type='hidden' name='sql9' value=\"$sql9\"></div>";
include "page_footer.inc";
}
?>