Hi can somebody help me with this pagination coding.I have use this pagination to display searched items. it searches and display 1-2 items. but once i click the next link it doesn’t display anything.i know where the problem is.here it is
$link = “search.php?page_no={$page_no}”;
please try to solove it.
thanks
<?php
/* ======== search.php =======
@$advance_search = advance_search($_POST[‘condition’],$_POST[‘model’],$_POST[‘fuel_type’],$_POST[‘price’]);
@$num_of_records = show_count_for_advance_search($_POST[‘make’],$_POST[‘year’],$_POST[‘trans’],$
$no_of_rows = count($advance_search);
$display_items = 2;
if (!isset($_GET[‘page_no’])){
$start_no = 1;
}
if (@$_GET[‘page_no’] != ”){
if ($_GET[‘page_no’] == 1){
$start_no = $display_items;
}
if ($_GET[‘page_no’] > 1){
$start_no = ($_GET[‘page_no’]) * $display_items;
}
}
if ($num_of_records < $display_items){
$link_message = “Showing 1 to {$num_of_records} of {$num_of_records}”;
@$page_message = “Page ” . (@$_GET[‘page_no’] + 1) . ” of {$no_of_pages}”;
}else{
$no_of_pages = ceil($num_of_records/$display_items);
@$page_no = $_GET[‘page_no’] + 1;
//if ($_GET[‘type’] == ‘advance’){
if ($_POST[‘condition’]!=’0′){
//@$link_concat .= “vehical_condition=”.$_POST[‘condition’];
@$link_concat .= “vehical_condition='”.$_POST[‘condition’].”‘”;
}
if ($_POST[‘make’]!=’0′){
@$link_concat .= “&vehical_make='”.$_POST[‘make’].”‘”;
}
if ($_POST[‘model’]!=’0′){
@$link_concat .= “&vehical_model='”.$_POST[‘model’].”‘”;
}
if ($_POST[‘year’]!=’0′){
@$link_concat .= “&manifac_year='”.$_POST[‘year’].”‘”;
}
if ($_POST[‘fuel_type’]!=’0′){
@$link_concat .= “&fuel_type='”.$_POST[‘fuel_type’].”‘”;
}
if ($_POST[‘trans’]!=’0′){
@$link_concat .= “&transmission='”.$_POST[‘trans’].”‘”;
}
if ($_POST[‘price’]!=’0′){
@$link_concat .= “&price='”.$_POST[‘price’].”‘”;
}
/*problem comes here*/ $link = “search.php?page_no={$page_no}”;
$set_pages = $page_no * $display_items;
$remain_items = $num_of_records – $set_pages;
$condition = ($page_no + 1) * $display_items;
if($condition < @$tot_itmes){
$nextLink=”<a href = $link class =’industry_pag_links’>Next Page ></a>”;
}
if ($remain_items > 0){
$nextLink=”<a href = $link class =’industry_pag_links’>Next Page ></a>”;
if ($remain_items < $display_items){
$end_no_remain = $page_no * $display_items;
}else{
$end_no_remain = $page_no * $display_items;
}
}
if ($remain_items <= 0){
$end_no_remain = $num_of_records;
}
if ($remain_items == $num_of_records){
$end_no_remain = $remain_items;
}
if(@$_GET[‘page_no’]==0){
$start_no = ‘1’;
}
if(@$_GET[‘page_no’] > 0){
$page_no = $_GET[‘page_no’]-1;
$linkPrivous = “search.php?$link_concat&page_no={$page_no}”;
$previous = ‘previous’;
$previousLink = “<a href = $linkPrivous class=’industry_pag_links’>< Previous</a>”;
}
@$link_message = “$previousLink Displaying $start_no to $end_no_remain of $num_of_records $nextLink”;
@$page_message = “Page ” . (@$_GET[‘page_no’] + 1) . ” of {$no_of_pages}”;
}
if($no_of_rows > 0){
// pagination display
echo “<div align=’center’>”;
if ($num_of_records > 0){
echo $link_message;
}
echo “</div>”;
echo “<br />”;
// end of pagination display
for ($i=0; $i<$no_of_rows; $i++){
echo “<div id=’results’>”;
// display results in a table
echo “<table border=’1′ bordercolor=’#3399CC’ cellspacing=’0′ width=’500′ height=’163′>”;
?>
<tr>
<td width=”26%” height=”33″> </td>
<td width=”18%”><?php echo $advance_search[$i][‘vehical_make’]; ?></td>
<td width=”20%”><?php echo $advance_search[$i][‘vehical_model’]; ?></td>
<td colspan=”2″>2009/03/04 12:25:30</td>
</tr>
<tr>
<?php echo “<tr><td rowspan=’3′><img src=”car_display_create.php?vehical_id=”.$advance_search[$i][‘vehical_id’].”” width=”100″ height=”100″></td>”; ?>
<!–<td rowspan=”3″><img src=”car_display_create.php?vehical_id=”.$view_users[$i][‘vehical_id’].”” width=”100″ height=”100″></td> –>
<td height=”49″>Condition</td>
<td><?php echo $advance_search[$i][‘vehical_condition’]; ?></td>
<td width=”19%”>Transmission</td>
<td width=”17%”><?php echo $advance_search[$i][‘transmission’]; ?></td>
</tr>
<tr>
<td height=”45″>Year</td>
<td><?php echo $advance_search[$i][‘manifac_year’]; ?></td>
<td>Fuel Type</td>
<td><?php echo $advance_search[$i][‘fuel_type’]; ?></td>
</tr>
<tr>
<td rowspan=”2″>Engine Capacity</td>
<td rowspan=”2″><?php echo $advance_search[$i][‘engine_capa’]; ?></td>
<td rowspan=”2″>Price</td>
<td rowspan=”2″><?php echo $advance_search[$i][‘price’]; ?></td>
</tr>
<tr>
<?php echo “<td height=”27″><a href=”car_display.php?task=1 & vehical_id=”.$advance_search[$i][‘vehical_id’].””>View Full Details</a></td></tr>”; ?>
<!– <td height=”27″><a href=”car_display.php?task=1″>Click here to view details</a></td> –>
</tr>
<?php
echo “</table>n”;
echo “</div>”;
echo “<br>”;
}
}
// pagination display
echo “<div align=’center’>”;
if ($num_of_records > 0){
echo $link_message;
}
echo “</div>”;
// end of pagination display
?>
function advance_search($cond,$make,$model,$year,$fuel_type,$trans,$price)
{
global $connection;
$display_items = 2;
@$page_no = $_GET[‘page_no’];
if (isset($_GET[‘page_no’])){
if ($_GET[‘page_no’] != ”){
if ($_GET[‘page_no’] == 0){
$start_no_sql = 0;
$end_no_sql = $display_items;
}else{
$start_no_sql = $page_no * $display_items;
$end_no_sql = $display_items;
}
}
}else{
$start_no_sql = 0;
$end_no_sql = $display_items;
}
$limit = ” Limit {$start_no_sql}, {$end_no_sql}”;
$sql = “Select * From vehicals where”;
if ($cond != ‘0’)
{
$sql .= ” vehical_condition = ‘”.$cond.”‘”;
if(($make!=”0″) || ($model!=”0″) || ($year!=”0″) || ($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($make != ‘0’)
{
$sql .= ” vehical_make = ‘”.$make.”‘”;
if(($model!=”0″) || ($year!=”0″) || ($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($model != ‘0’)
{
$sql .= ” vehical_model = ‘”.$model.”‘”;
if(($year!=”0″) || ($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($year != ‘0’)
{
$sql .= ” manifac_year = ‘”.$year.”‘”;
if(($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($fuel_type != ‘0’)
{
$sql .= ” fuel_type = ‘”.$fuel_type.”‘”;
if(($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($trans != ‘0’)
{
$sql .= ” transmission = ‘”.$trans.”‘”;
if(($price!=”0″))
{
$sql.=” and “;
}
}
if ($price != ‘0’)
{
$sql .= ” price = ‘”.$price.”‘”;
}
$sql .= $limit;
//die($sql);
$results = mysql_query($sql,$connection);
if ($results)
{
$i = 0;
$advance_search = array();
while ($row = mysql_fetch_array($results)){
$advance_search[$i][‘vehical_id’] = $row[‘vehical_id’];
$advance_search[$i][‘vehical_condition’] = $row[‘vehical_condition’];
$advance_search[$i][‘vehical_make’] = $row[‘vehical_make’];
$advance_search[$i][‘vehical_model’] = $row[‘vehical_model’];
$advance_search[$i][‘manifac_year’] = $row[‘manifac_year’];
$advance_search[$i][‘fuel_type’] = $row[‘fuel_type’];
$advance_search[$i][‘transmission’] = $row[‘transmission’];
$advance_search[$i][‘engine_capa’] = $row[‘engine_capa’];
$advance_search[$i][‘price’] = $row[‘price’];
$i++;
}
return $advance_search;
}
}
function show_count_for_advance_search($cond,$make,$model,$year,$fuel_type,$trans,$price)
{
global $connection;
$sql = “Select * From vehicals where”;
if ($cond != ‘0’)
{
$sql .= ” vehical_condition = ‘”.$cond.”‘”;
if(($make!=”0″) || ($model!=”0″) || ($year!=”0″) || ($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($make != ‘0’)
{
$sql .= ” vehical_make = ‘”.$make.”‘”;
if(($model!=”0″) || ($year!=”0″) || ($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($model != ‘0’)
{
$sql .= ” vehical_model = ‘”.$model.”‘”;
if(($year!=”0″) || ($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($year != ‘0’)
{
$sql .= ” manifac_year = ‘”.$year.”‘”;
if(($fuel_type!=”0″) || ($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($fuel_type != ‘0’)
{
$sql .= ” fuel_type = ‘”.$fuel_type.”‘”;
if(($trans!=”0″) || ($price!=”0″))
{
$sql.=” and “;
}
}
if ($trans != ‘0’)
{
$sql .= ” transmission = ‘”.$trans.”‘”;
if(($price!=”0″))
{
$sql.=” and “;
}
}
if ($price != ‘0’)
{
$sql .= ” price = ‘”.$price.”‘”;
}
if ($results = mysql_query($sql,$connection))
{
$num_of_records = mysql_num_rows($results);
return $num_of_records;
}
}
/* === end of searh.php ===