【php开源代码栏目提醒】:网学会员,鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“Books.php”一文,供大家参考学习!
<?php
include ("./common.php");
include ("./Header.php");
include ("./Footer.php");
session_start();
$filename = "Books.php";
$tpl = new Template($app_path);
$tpl->load_file("Books.html", "main");
$tpl->load_file($header_filename, "Header");
$tpl->load_file($footer_filename, "Footer");
$tpl->set_var("FileName", $filename);
Menu_show();
Footer_show();
Results_show();
Search_show();
AdvMenu_show();
Total_show();
$tpl->parse("Header", false);
$tpl->parse("Footer", false);
$tpl->pparse("main", false);
//********************************************************************************
function Results_show()
{
global $tpl;
global $db;
global $sResultsErr;
$sWhere = "";
$sOrder = "";
$sSQL = "";
$HasParam = false;
$tpl->set_var("TransitParams", "category_id=" . tourl(strip(get_param("category_id"))) . "&name=" . tourl(strip(get_param("name"))) . "&pricemin=" . tourl(strip(get_param("pricemin"))) . "&pricemax=" . tourl(strip(get_param("pricemax"))) . "&author=" . tourl(strip(get_param("author"))) . "&");
$tpl->set_var("FormParams", "category_id=" . tourl(strip(get_param("category_id"))) . "&name=" . tourl(strip(get_param("name"))) . "&pricemin=" . tourl(strip(get_param("pricemin"))) . "&pricemax=" . tourl(strip(get_param("pricemax"))) . "&author=" . tourl(strip(get_param("author"))) . "&");
// Build WHERE statement
$pauthor = get_param("author");
if(strlen($pauthor))
{
$HasParam = true;
$sWhere .= "i.author like " . tosql("%".$pauthor ."%", "Text");
}
$pcategory_id = get_param("category_id");
if(is_number($pcategory_id) && strlen($pcategory_id))
$pcategory_id = round($pcategory_id);
else
$pcategory_id = "";
if(strlen($pcategory_id))
{
if ($sWhere != "") $sWhere .= " and ";
$HasParam = true;
$sWhere .= "i.category_id=" . $pcategory_id;
}
$pname = get_param("name");
if(strlen($pname))
{
if ($sWhere != "") $sWhere .= " and ";
$HasParam = true;
$sWhere .= "i.name like " . to
sql("%".$pname ."%", "Text");
}
$ppricemax = get_param("pricemax");
if(is_number($ppricemax) && strlen($ppricemax))
$ppricemax = round($ppricemax);
else
$ppricemax = "";
if(strlen($ppricemax))
{
if ($sWhere != "") $sWhere .= " and ";
$HasParam = true;
$sWhere .= "i.price<" . $ppricemax;
}
$ppricemin = get_param("pricemin");
if(is_number($ppricemin) && strlen($ppricemin))
$ppricemin = round($ppricemin);
else
$ppricemin = "";
if(strlen($ppricemin))
{
if ($sWhere != "") $sWhere .= " and ";
$HasParam = true;
$sWhere .= "i.price>" . $ppricemin;
}
if($HasParam)
$sWhere = " AND (" . $sWhere . ")";
$sDirection = "";
$sSortParams = "";
// Build ORDER statement
$sOrder = " order by i.name Asc";
$iSort = get_param("FormResults_Sorting");
$iSorted = get_param("FormResults_Sorted");
if(!$iSort)
{
$tpl->set_var("Form_Sorting", "");
}
else
{
if($iSort == $iSorted)
{
$tpl->set_var("Form_Sorting", "");
$sDirection = " DESC";
$sSortParams = "FormResults_Sorting=" . $iSort . "&FormResults_Sorted=" . $iSort . "&";
}
else
{
$tpl->set_var("Form_Sorting", $iSort);
$sDirection = " ASC";
$sSortParams = "FormResults_Sorting=" . $iSort . "&FormResults_Sorted=" . "&";
}
if ($iSort == 1) $sOrder = " order by i.name" . $sDirection;
if ($iSort == 2) $sOrder = " order by i.author" . $sDirection;
if ($iSort == 3) $sOrder = " order by i.price" . $sDirection;
if ($iSort == 4) $sOrder = " order by c.name" . $sDirection;
if ($iSort == 5) $sOrder = " order by i.image_url" . $sDirection;
}
// Build full SQL statement
$sSQL = "select i.author as i_author, " .
"i.category_id as i_category_id, " .
"i.image_url as i_image_url, " .
"i.item_id as i_item_id, " .
"i.name as i_name, " .
"i.price as i_price, " .
"c.category_id as c_category_id, " .
"c.name as c_name " .
" from items i, categories c" .
" where c.category_id=i.category_id ";
$sSQL .= $sWhere . $sOrder;
$tpl->set_var("SortParams", $sSortParams);
// Execute SQL statement
$db->query($sSQL);
// Select current page
$iPage = get_param("FormResults_Page");
if(!strlen($iPage)) $iPage = 1;
$RecordsPerPage = 20;
if(($iPage - 1) * $RecordsPerPage != 0)
$db->seek(($iPage - 1) * $RecordsPerPage);
$iCounter = 0;
if($db->next_record())
{
// Show main table based on SQL query
do
{
$fldname = $db->f("i_name");
$fldauthor = $db->f("i_author");
$fldprice = $db->f("i_price");
$fldcategory_id = $db->f("c_name");
$fldimage_url = $db->f("i_image_url");
$fldimage_url="<img border=0 src=" . $fldimage_url . ">";
$tpl->set_var("name", tohtml($fldname));
$tpl->set_var("name_URLLink", "BookDetail.php");
$tpl->set_var("Prm