Jump to content

pagination probllem??


darkfreaks

Recommended Posts

My code is only returning the previous button and no data? is there anyway to fix this? ???

 

 

 

 

 

 

 

 

 

 

<?php
$page =(isset($_GET['page']))?$_GET['page']:1;
$max_results = 25;
$from = (($page * $max_results) - $max_results);
function clean($string){
    $new = trim(strip_tags(mysql_real_escape_string(htmlentities($string))));
    return $new;
}
if (isset($_POST['Search'])) {
    $total_results = "SELECT * FROM jobs WHERE NOW() < expires  AND paid = '1' ";
    if ($_POST['keyword'] != '') {
        $find = strtoupper(clean($_POST['keyword']));
	$location = clean($_POST['location']);
	$category = clean($_POST['category']);

        if (($_POST['category'] != '') && ($_POST['location'] != '')) {
            $total_results .= "AND category = '" .$category."' OR location = '" .$location . "'OR title LIKE '%$find%'";;
        } 
	elseif (($_POST['category'] != '') && ($_POST['location'] == '')) {
           $total_results .= "AND category = '" . $category . "' OR title LIKE '%$find%' ";;
        } 
	elseif (($_POST['category'] == '') && ($_POST['location'] != '')) {
           $total_results .= " AND location = '" . $location ."' OR title LIKE '%$find%'";;
        }
        else {
		$total_results .= "AND title LIKE '%$find%'";
        }
	$search = true;
    }
    else {
        if ($_POST['location'] != '') { 
		if ($_POST['category'] == '') { 
			$total_results .= "AND location = '" . $location ."' ";
			$search = true;
		} 
        }
        if ($_POST['category'] != '') { 
		if ($_POST['location'] == '') { 
			$total_results .= "AND category = '" . $category."' ";
			$search = true;
		} 
        } 
        if ($_POST['category'] != '' && $_POST['location'] != '') { 
			$total_results .= "AND category = '" . $category ."' AND location = '" . $location ."' ";
			$search = true;
        } 
    } 

    if ($search) {
	$totalrows = mysql_query($total_results) or die(mysql_error());
	$num = mysql_num_rows($totalrows);
	$total_pages = ceil($num / $max_results);

	$total_results .="ORDER BY job_id DESC LIMIT $from,$max_results";
	$aa = mysql_query($total_results) or die(mysql_error());
	while ($row = mysql_fetch_array($aa)) {
             echo "
			<tr>
				<td align='left' valign='top' bgcolor='#F2F5F9'>
					<b><a href='view-job.php?job_id={$row['job_id']}'>" .stripslashes($row['title']) . "</a></b> <br>" . stripslashes($row['employer']) ."
				</td>
				<td align='left' valign='top' bgcolor='#F2F5F9'>
					{$row['city']}, {$row['location']}
				</td>
				<td align='center' valign='top' bgcolor='#F2F5F9' width='70' class='small_10'>" .
                        date('M d, y', strtotime($row['date'])) . "
				</td>
		</tr>";
      } // End While
    }
    echo "</table>";
    echo "<p align='right'>";

    if ($page <= 1) {
        echo " <a href='#'><<</a> ";
    }
    else {
	$prev = ($page - 1);
	echo " <a href=\"" . $_SERVER['PHP_SELF'] . "?page=$prev\"><<</a> ";
    }
    for ($i = 1; $i <= $total_pages; $i++) {
	if (($page) == $i) {
		echo "[$i] ";
	}
	else {
		echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=$i\">$i</a>&nbsp";
	}
    }
    if ($page < $total_pages) {
	$next = ($page + 1);
	echo " <a href=\"" . $_SERVER['PHP_SELF'] . "?page=$next\"> >></a> ";
    }
    echo '</p>';
} // End if form was submitted
include_once ('../includes/footer.htm');
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.