Jump to content

Recommended Posts

Here you go.

 

If have any issues describe it or better yet show me your working page.

 

The script assumes the page is index.php

If you need it called different, just make a folder named cars or something and drop this script inside named index.php ......otherwise changes would have to be made.

 

<?php
//get the url from the address bar and redirect to script name
$url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$url .= "?".$query_string;
}
if($url == "http://".$_SERVER['HTTP_HOST']){
$redirect_to = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
header("Location: $redirect_to");
}

if (!isset($_GET['make'])) {
$_GET['make'] = "All";
}
?>
<form name="input" action="" method="GET">
Make: <Select name="make">
<option "Input" value="<?php echo $_GET['make']; ?>"><?php echo $_GET['make']; ?></option>
<option value="All">All</option>
<option value="Ford">ford</option>
<option value="BMW">BMW</option>
<option value="Honda">Honda</option>
<option value="Lexus">Lexus</option>
</select>

<?php
if (!isset($_GET['model'])) {
$_GET['model'] = "All";
}
?>

Model: <Select name="model">
<option "Input" value="<?php echo $_GET['model']; ?>"><?php echo $_GET['model']; ?></option>
<option value="All">All</option>
<option value="Civic">Civic</option>
<option value="3 Series">3 Series</option>
<option value="Fiesta">Fiesta</option>
<option value="IS200">IS200</option>
</select>

<?php
if (!isset($_GET['fuel'])) {
$_GET['fuel'] = "Any";
}
?>

Fuel: <Select name="fuel">
<option "Input" value="<?php echo $_GET['fuel']; ?>"><?php echo $_GET['fuel']; ?></option>
<option value="Any">Any</option>
<option value="Petrol">Petrol</option>
<option value="Diesel">Diesel</option>
</select>

<?php
if (!isset($_GET['location'])) {
$_GET['location'] = "All";
}
?>
Location: <Select name="location">
<option "Input" value="<?php echo $_GET['location']; ?>"><?php echo $_GET['location']; ?></option>
<option value="All">All</option>
<option value="UK">UK</option>
<option value="London">London</option>
<option value="Kent">Kent</option>
</select>

<?php
if (!is_numeric($_GET['page']) || !isset($_GET['page']) || $_GET['page'] == 0 || empty($_GET['page'])) {
$_GET['page'] = 1;
}
?>
Page:<input onfocus="this.value=''" size="15" type="text" name="page" value="<?php echo $_GET['page']; ?>"/>

<input type="submit" value="Search Cars" />
</form>


<?php
//include 'db.inc.php';

$con = mysql_connect("localhost","db_username","db_password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);


//variables from selection form
$make = mysql_real_escape_string(trim($_GET['make']));
$model = mysql_real_escape_string(trim($_GET['model']));
$fuel = mysql_real_escape_string(trim($_GET['fuel']));
$location = mysql_real_escape_string(trim($_GET['location']));

$startrow = 0;
$posts_per_page = 30;

$nav_get = $_GET['page'];

if (!isset($_GET['page']) || !is_numeric($_GET['page']) || empty($_GET['page'])) {
$startrow = 0;
$_GET['page'] = 1;
$nav_get = 1;
} else {
$convert = $nav_get * $posts_per_page -$posts_per_page;
$startrow = (int)$convert;
}
$prev = $nav_get - 1;
if ($prev < 1) {
$prev =1;
}
$next = $nav_get +1;
$navigation_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);

if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$navigation_url .= "?".$query_string;
}

$navigation_url = trim($navigation_url,$nav_get);

//you can change these to your needs
if ($url == "http://".$_SERVER['HTTP_HOST'] || $url == "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']) {
$navigation_url = "$navigation_url?&page=";
}

//default query
$query = "SELECT * FROM `cars`";

//count the selections for queries
$query_count = 0;

//set queries and associate WHERE,AND
if(isset($_GET['make']) && $_GET['make'] != "All" && $_GET['make'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= " $where_and Make='$make'";
}

if(isset($_GET['model']) && $_GET['model'] != "All" && $_GET['model'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= " $where_and Model='$model'";
}

if(isset($_GET['fuel']) && $_GET['fuel'] != "Any" && $_GET['fuel'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= "  $where_and Fuel='$fuel'";
}

if(isset($_GET['location']) && $_GET['location'] != "All" && $_GET['location'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= "  $where_and Location='$location'";
}

//find number of total count of GETs for each result minus the limits
$total_posts = mysql_num_rows($query);

//final query to add the order and limit
$query .=" ORDER BY id DESC LIMIT $startrow,$posts_per_page";

//echo $query."<br />";//query built from values above depending on selections
$result = mysql_query($query);

$lastposts = $total_posts - $posts_per_page;
$nextposts = $total_posts +1;
$total_posts_pages = $total_posts / $posts_per_page;
list($int,$dec)=explode('.', $total_posts_pages);
$int_pages = $int +1;
$total_pages = $total_posts / $posts_per_page;
$page_number = $startrow / $posts_per_page + 1;
if ($nextposts >= $int_pages) {
$nextposts = $int_pages;
$page_one = 1;
}
if (!$_GET['page']) {
$_GET['page'] = 1;
}
if ($page_number >= $int_pages+1) {
$_GET['page'] = $int_pages;
}
if ($_GET['page'] <= 0) {
$_GET['page'] = 1;
}
if ($page_number <= 0) {
$page_number = 1;
}
if ($total_posts == 0){
echo '<h2>No results found.</h2>';
}

echo "Page $page_number of $int_pages - $total_posts Results<br />";

//the page navigation hyperlinks
echo "[<a href='./?page=1'><b>New</b></a>]";
echo "[<a href='$navigation_url$page_one'><b>First</b></a>]";
if ($page_number > 1){
     echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]';
    }
if ($next <= $prev) {
$next = $next+1;
}
echo "[$page_number]";
if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]';
    }

if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }
//check if results
if(!$result){
echo "No Results <br />";
} else {

echo "<table class='ex1' border='0' width='120%' style=text-align:center; cellpadding='6' cellspacing='0'></tr>";

while($row = mysql_fetch_array($result)) {

  echo "<tr style=font-family:verdana;font-size:80%;>";

    echo "<td width=13%>" . $row[""] . "<img src=\"" . $row["Photo"] . "\"></a>";
    echo '<td width="14%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Make'] . '</a></td>';   
    echo '<td width="5%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Model'] . '</a></td>';
    echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Fuel'] . '</a></td>';
    echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Location'] . '</a></td>';
       
echo "</tr>";
}
  

echo "</table>";
}

//the page navigation hyperlinks
echo "[<a href='./?page=1'><b>New</b></a>]";
echo "[<a href='$navigation_url$page_one'><b>First</b></a>]";
if ($page_number > 1){
     echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]';
    }
if ($next <= $prev) {
$next = $next+1;
}
echo "[$page_number]";
if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]';
    }

if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }


}

mysql_close($con);

?>

 

My nephew was blabbing to me entire time did this, hopefully I got it right.

Hi QuickOldCar!

 

Thanks for getting back to me! You must be getting a little tired of me by now.... :shy:

Your time and effort is much appreciated! I owe you a few beers at this point!

 

Yeah that code kinda works! I did have to remove the

 } mysql_close($con);

to get it to display the results.

 

At the moment their is still an error appearing, but still works with the error showing.

There is one thing I would like to change, if possible. Where you have the text box showing page no: is it possible to remove this and have a simple next and previous page links?

 

Here is the url of the index.php  - http://cars.netau.net/     - (The database data is only test data(91 records))

 

I would ideally like to display 20 records per page, is it a matter of simply changing the

$posts_per_page = 30;

number to change this? or is it best to leave it at 30?

 

Thanks ever so much! You are the only one who's php help requests make any sense to me!

 

oops sorry, yeah I knew something wouldn't work.

This should.

 


<?php
//get the url from the address bar and redirect to script name
$url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);



$url .= "?".$query_string;



}
if($url == "http://".$_SERVER['HTTP_HOST']){
$redirect_to = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
header("Location: $redirect_to");
}

if (!isset($_GET['make'])) {
$_GET['make'] = "All";
}
?>
<form name="input" action="" method="GET">
Make: <Select name="make">
<option "Input" value="<?php echo $_GET['make']; ?>"><?php echo $_GET['make']; ?></option>
<option value="All">All</option>
<option value="Ford">ford</option>
<option value="BMW">BMW</option>
<option value="Honda">Honda</option>
<option value="Lexus">Lexus</option>
</select>

<?php
if (!isset($_GET['model'])) {
$_GET['model'] = "All";
}
?>

Model: <Select name="model">
<option "Input" value="<?php echo $_GET['model']; ?>"><?php echo $_GET['model']; ?></option>
<option value="All">All</option>
<option value="Civic">Civic</option>
<option value="3 Series">3 Series</option>
<option value="Fiesta">Fiesta</option>
<option value="IS200">IS200</option>
</select>

<?php
if (!isset($_GET['fuel'])) {
$_GET['fuel'] = "Any";
}
?>

Fuel: <Select name="fuel">
<option "Input" value="<?php echo $_GET['fuel']; ?>"><?php echo $_GET['fuel']; ?></option>
<option value="Any">Any</option>
<option value="Petrol">Petrol</option>
<option value="Diesel">Diesel</option>
</select>

<?php
if (!isset($_GET['location'])) {
$_GET['location'] = "All";
}
?>
Location: <Select name="location">
<option "Input" value="<?php echo $_GET['location']; ?>"><?php echo $_GET['location']; ?></option>
<option value="All">All</option>
<option value="UK">UK</option>
<option value="London">London</option>
<option value="Kent">Kent</option>
</select>

<?php
if (!is_numeric($_GET['page']) || !isset($_GET['page']) || $_GET['page'] == 0 || empty($_GET['page'])) {
$_GET['page'] = 1;
}
?>
Page:<input onfocus="this.value=''" size="15" type="text" name="page" value="<?php echo $_GET['page']; ?>"/>

<input type="submit" value="Search Cars" />
</form>


<?php
//include 'db.inc.php';

$con = mysql_connect("localhost","db_username","db_password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);


//variables from selection form
$make = mysql_real_escape_string(trim($_GET['make']));
$model = mysql_real_escape_string(trim($_GET['model']));
$fuel = mysql_real_escape_string(trim($_GET['fuel']));
$location = mysql_real_escape_string(trim($_GET['location']));

$startrow = 0;
$posts_per_page = 20;

$nav_get = $_GET['page'];

if (!isset($_GET['page']) || !is_numeric($_GET['page']) || empty($_GET['page'])) {
$startrow = 0;
$_GET['page'] = 1;
$nav_get = 1;
} else {
$convert = $nav_get * $posts_per_page -$posts_per_page;
$startrow = (int)$convert;
}
$prev = $nav_get - 1;
if ($prev < 1) {
$prev =1;
}
$next = $nav_get +1;
$navigation_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);

if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);



$navigation_url .= "?".$query_string;
}

$navigation_url = trim($navigation_url,$nav_get);

//you can change these to your needs
if ($url == "http://".$_SERVER['HTTP_HOST'] || $url == "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']) {
$navigation_url = "$navigation_url?&page=";
}

//default query
$query = "SELECT * FROM `cars`";

//count the selections for queries
$query_count = 0;

//set queries and associate WHERE,AND
if(isset($_GET['make']) && $_GET['make'] != "All" && $_GET['make'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= " $where_and Make='$make'";
}

if(isset($_GET['model']) && $_GET['model'] != "All" && $_GET['model'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= " $where_and Model='$model'";
}

if(isset($_GET['fuel']) && $_GET['fuel'] != "Any" && $_GET['fuel'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= "  $where_and Fuel='$fuel'";
}

if(isset($_GET['location']) && $_GET['location'] != "All" && $_GET['location'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= "  $where_and Location='$location'";
}

//find number of total count of GETs for each result minus the limits
$totals = mysql_query($query);
$total_posts = mysql_num_rows($totals);

//final query to add the order and limit
$query .=" 'ORDER BY id DESC LIMIT $startrow,$posts_per_page'";

//echo $query."<br />";//query built from values above depending on selections
$result = mysql_query($query);

$lastposts = $total_posts - $posts_per_page;
$nextposts = $total_posts +1;
$total_posts_pages = $total_posts / $posts_per_page;
list($int,$dec)=explode('.', $total_posts_pages);
$int_pages = $int +1;
$total_pages = $total_posts / $posts_per_page;
$page_number = $startrow / $posts_per_page + 1;
if ($nextposts >= $int_pages) {
$nextposts = $int_pages;
$page_one = 1;
}
if (!$_GET['page']) {
$_GET['page'] = 1;
}
if ($page_number >= $int_pages+1) {
$_GET['page'] = $int_pages;
}
if ($_GET['page'] <= 0) {
$_GET['page'] = 1;
}
if ($page_number <= 0) {
$page_number = 1;
}
if ($total_posts == 0){
echo '<h2>No results found.</h2>';
}

echo "Page $page_number of $int_pages - $total_posts Results<br />";

//the page navigation hyperlinks
echo "[<a href='./?page=1'><b>New</b></a>]";
echo "[<a href='$navigation_url$page_one'><b>First</b></a>]";
if ($page_number > 1){
     echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]';
    }
if ($next <= $prev) {
$next = $next+1;
}
echo "[$page_number]";
if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]';
    }

if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }
//check if results
if(!$result){
echo "No Results <br />";
} else {

echo "<table class='ex1' border='0' width='120%' style=text-align:center; cellpadding='6' cellspacing='0'></tr>";

while($row = mysql_fetch_array($result)) {

  echo "<tr style=font-family:verdana;font-size:80%;>";

    echo "<td width=13%>" . $row[""] . "<img src=\"" . $row["Photo"] . "\"></a>";
    echo '<td width="14%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Make'] . '</a></td>';   
    echo '<td width="5%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Model'] . '</a></td>';
    echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Fuel'] . '</a></td>';
    echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Location'] . '</a></td>';
       
echo "</tr>";
}
  

echo "</table>";
}

//the page navigation hyperlinks
echo "[<a href='./?page=1'><b>New</b></a>]";
echo "[<a href='$navigation_url$page_one'><b>First</b></a>]";
if ($page_number > 1){
     echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]';
    }
if ($next <= $prev) {
$next = $next+1;
}
echo "[$page_number]";
if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]';
    }

if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }

?>

 

As for the buttons will see what I can do.

See if this works and actually displays a Next to page 2 and proper results now.

 

It didn't set the total_posts because the query was failing.

 

Results set to 20 per page now.

Actually I made another mistake, I addeda quote when needed to remove a quote in last query.

 

<?php
//get the url from the address bar and redirect to script name
$url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);





$url .= "?".$query_string;





}
if($url == "http://".$_SERVER['HTTP_HOST']){
$redirect_to = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
header("Location: $redirect_to");
}

if (!isset($_GET['make'])) {
$_GET['make'] = "All";
}
?>
<form name="input" action="" method="GET">
Make: <Select name="make">
<option "Input" value="<?php echo $_GET['make']; ?>"><?php echo $_GET['make']; ?></option>
<option value="All">All</option>
<option value="Ford">ford</option>
<option value="BMW">BMW</option>
<option value="Honda">Honda</option>
<option value="Lexus">Lexus</option>
</select>

<?php
if (!isset($_GET['model'])) {
$_GET['model'] = "All";
}
?>

Model: <Select name="model">
<option "Input" value="<?php echo $_GET['model']; ?>"><?php echo $_GET['model']; ?></option>
<option value="All">All</option>
<option value="Civic">Civic</option>
<option value="3 Series">3 Series</option>
<option value="Fiesta">Fiesta</option>
<option value="IS200">IS200</option>
</select>

<?php
if (!isset($_GET['fuel'])) {
$_GET['fuel'] = "Any";
}
?>

Fuel: <Select name="fuel">
<option "Input" value="<?php echo $_GET['fuel']; ?>"><?php echo $_GET['fuel']; ?></option>
<option value="Any">Any</option>
<option value="Petrol">Petrol</option>
<option value="Diesel">Diesel</option>
</select>

<?php
if (!isset($_GET['location'])) {
$_GET['location'] = "All";
}
?>
Location: <Select name="location">
<option "Input" value="<?php echo $_GET['location']; ?>"><?php echo $_GET['location']; ?></option>
<option value="All">All</option>
<option value="UK">UK</option>
<option value="London">London</option>
<option value="Kent">Kent</option>
</select>

<?php
if (!is_numeric($_GET['page']) || !isset($_GET['page']) || $_GET['page'] == 0 || empty($_GET['page'])) {
$_GET['page'] = 1;
}
?>
Page:<input onfocus="this.value=''" size="15" type="text" name="page" value="<?php echo $_GET['page']; ?>"/>

<input type="submit" value="Search Cars" />
</form>


<?php
//include 'db.inc.php';

$con = mysql_connect("localhost","db_username","db_password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);


//variables from selection form
$make = mysql_real_escape_string(trim($_GET['make']));
$model = mysql_real_escape_string(trim($_GET['model']));
$fuel = mysql_real_escape_string(trim($_GET['fuel']));
$location = mysql_real_escape_string(trim($_GET['location']));

$startrow = 0;
$posts_per_page = 20;

$nav_get = $_GET['page'];

if (!isset($_GET['page']) || !is_numeric($_GET['page']) || empty($_GET['page'])) {
$startrow = 0;
$_GET['page'] = 1;
$nav_get = 1;
} else {
$convert = $nav_get * $posts_per_page -$posts_per_page;
$startrow = (int)$convert;
}
$prev = $nav_get - 1;
if ($prev < 1) {
$prev =1;
}
$next = $nav_get +1;
$navigation_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);

if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);





$navigation_url .= "?".$query_string;
}

$navigation_url = trim($navigation_url,$nav_get);

//you can change these to your needs
if ($url == "http://".$_SERVER['HTTP_HOST'] || $url == "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']) {
$navigation_url = "$navigation_url?&page=";
}

//default query
$query = "SELECT * FROM `cars`";

//count the selections for queries
$query_count = 0;

//set queries and associate WHERE,AND
if(isset($_GET['make']) && $_GET['make'] != "All" && $_GET['make'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= " $where_and Make='$make'";
}

if(isset($_GET['model']) && $_GET['model'] != "All" && $_GET['model'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= " $where_and Model='$model'";
}

if(isset($_GET['fuel']) && $_GET['fuel'] != "Any" && $_GET['fuel'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= "  $where_and Fuel='$fuel'";
}

if(isset($_GET['location']) && $_GET['location'] != "All" && $_GET['location'] != ""){
$query_count = $query_count +1;
if($query_count == 1) {
$where_and = "WHERE";
} else {
$where_and = "AND";
}
//if selected adds to query
$query .= "  $where_and Location='$location'";
}

//find number of total count of GETs for each result minus the limits
$totals = mysql_query($query);
$total_posts = mysql_num_rows($totals);

//final query to add the order and limit
$query .=" ORDER BY id DESC LIMIT $startrow,$posts_per_page";

//echo $query."<br />";//query built from values above depending on selections
$result = mysql_query($query);

$lastposts = $total_posts - $posts_per_page;
$nextposts = $total_posts +1;
$total_posts_pages = $total_posts / $posts_per_page;
list($int,$dec)=explode('.', $total_posts_pages);
$int_pages = $int +1;
$total_pages = $total_posts / $posts_per_page;
$page_number = $startrow / $posts_per_page + 1;
if ($nextposts >= $int_pages) {
$nextposts = $int_pages;
$page_one = 1;
}
if (!$_GET['page']) {
$_GET['page'] = 1;
}
if ($page_number >= $int_pages+1) {
$_GET['page'] = $int_pages;
}
if ($_GET['page'] <= 0) {
$_GET['page'] = 1;
}
if ($page_number <= 0) {
$page_number = 1;
}
if ($total_posts == 0){
echo '<h2>No results found.</h2>';
}

echo "Page $page_number of $int_pages - $total_posts Results<br />";

//the page navigation hyperlinks
echo "[<a href='./?page=1'><b>New</b></a>]";
echo "[<a href='$navigation_url$page_one'><b>First</b></a>]";
if ($page_number > 1){
     echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]';
    }
if ($next <= $prev) {
$next = $next+1;
}
echo "[$page_number]";
if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]';
    }

if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }
//check if results
if(!$result){
echo "No Results <br />";
} else {

echo "<table class='ex1' border='0' width='120%' style=text-align:center; cellpadding='6' cellspacing='0'></tr>";

while($row = mysql_fetch_array($result)) {

  echo "<tr style=font-family:verdana;font-size:80%;>";

    echo "<td width=13%>" . $row[""] . "<img src=\"" . $row["Photo"] . "\"></a>";
    echo '<td width="14%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Make'] . '</a></td>';   
    echo '<td width="5%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Model'] . '</a></td>';
    echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Fuel'] . '</a></td>';
    echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Location'] . '</a></td>';
       
echo "</tr>";
}
  

echo "</table>";
}

//the page navigation hyperlinks
echo "[<a href='./?page=1'><b>New</b></a>]";
echo "[<a href='$navigation_url$page_one'><b>First</b></a>]";
if ($page_number > 1){
     echo '[<a href="'.$navigation_url.''.$prev.'"><b><<- Previous.. </b></a>]';
    }
if ($next <= $prev) {
$next = $next+1;
}
echo "[$page_number]";
if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$next.'"><b> ..Next ->></b></a>]';
    }

if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }

?>

:D You are a legend! :D

Thank you yet again! cant put my appreciation in words....

 

Now I can get on with building the rest of my website! :)

 

 

I don't know what I would do without your help! Genius, I take it you are a full time programmer? All codes working on 1st attempt!!!

 

Thank you once again! I hope I wasn't too much of a pain. :shy:

 

Aidan

 

 

 

 

 

 

 

 

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.