Jump to content

site search woes


davieboy

Recommended Posts

hey all im using this code

<?php
include_once('config.php');
$airline_search = !empty($_GET['airline_search']) ? $_GET['airline_search'] : 'ALL';
$airport_search = !empty($_GET['airport_search']) ? $_GET['airport_search'] : 'ALL';
$aircraft_search = !empty($_GET['aircraft_search']) ? $_GET['aircraft_search'] : 'ALL';
$keyword_search = !empty($_GET['keyword_search']) ? $_GET['keyword_search'] : 'ALL';


mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());

// If page number is set then use it, if not, set one!
$page = !isset($_GET['page']) ? '1' : $_GET['page'];

// Define the number of results per page
$max_results = 15;

// Figure out the limit for the query based on the current page number.
$from = (($page * $max_results) - $max_results);

// Specify the default SQL query
$sql = "SELECT * FROM photos WHERE status = 'accepted'";

// Amend the serach parameters if there are any
if (isset($_GET['$airline_search'])){
   $sql .= " AND airline LIKE '%$airline_search%'";
}
if (isset($_GET['$airport_search'])){
   $sql .= " AND location LIKE '%$airport_search%'";
}         
if (isset($_GET['$aircraft_search'])){
   $sql .= " AND aircraft LIKE '%$aircraft_search%'";
}
if (isset($_GET['$keyword_search'])) {
   $sql .= " AND comments LIKE '%$keyword_search%'";
}

// Run the query to get the total number of results.
$result = mysql_query($sql) or die(mysql_error());
$total_results = mysql_num_rows($result);

// Amend the limit and order by parameters and re-query
$sql .= " ORDER BY id LIMIT $from, $max_results";

// Re-run the query with additional constraints
$result = mysql_query($sql) or die(mysql_error());
if ($total_results < 1){
echo $sql;
   echo "Sorry, your search produced no results";
}
else {
echo $sql;
   echo "Your search produced $total_results results<br><br>\n";
while ($r=mysql_fetch_array($result))
{    
    $id=$r["id"];
$reg=$r["reg"];
$airline=$r["airline"];
    $status=$r["status"];
$uploaded=$r["awhen"];
$file_name=$r["file_name"];
$hits=$r["hits"];
$copyright=$r["copyright"];
$group_photo=$r["group_photo"];
$awhere=$r["awhere"];
$aircraft=$r["aircraft"];
$date_from_unix =$r["date_taken"];
$location = $r["location"];
$serial = $r["serials"];
$comments = $r["comments"];
{
   echo "ALL ECHO's CORRECTLY"

}
}

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Construct the base link...
$href = $_SERVER['PHP_SELF']."?";
foreach ($_GET as $k => $v){
   if ($k != "page"){
      $href .= "$k=$v&";
   }
}

//Previous and next links
$plink = "<< Previous";
$nlink = "Next >>";

echo "<center>";
// Build Previous Link
if($page > 1){
   $prev = ($page - 1);
   echo "<a href=\"{$href}page={$prev}\">{$plink}</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
   if(($page) == $i){
      echo "$i ";
   }
   else {
      echo "<a href=\"{$href}page={$i}\">{$i}</a> ";
   }
}

// Build Next Link
if($page < $total_pages){
   $next = ($page + 1);
   echo "<a href=\"{$href}page={$next}\">{$nlink}</a> ";
}
echo "</center>";
}
?>

 

but when searching and selecting options its not chosing the 'isset' part of the query

 

eg searching for 'airbus' the query its using is

SELECT * FROM photos WHERE status = 'accepted' ORDER BY id LIMIT 0, 15Your

it should be

SELECT * FROM photos WHERE status = 'accepted' and aircraft LIKE 'Airbus' ORDER BY id LIMIT 0, 15

 

tried all i can think of

Davdi

Link to comment
Share on other sites

have changed the 4 i had there.

 

code still not playing ball

 

www.saphotography.co.uk/search2.php

 

is this correct?

$airline_search = !empty($_GET['airline_search']) ? $_GET['airline_search'] : 'ALL';
$airport_search = !empty($_GET['airport_search']) ? $_GET['airport_search'] : 'ALL';
$aircraft_search = !empty($_GET['aircraft_search']) ? $_GET['aircraft_search'] : 'ALL';
$keyword_search = !empty($_GET['keyword_search']) ? $_GET['keyword_search'] : 'ALL';

Link to comment
Share on other sites

SELECT * FROM photos 
WHERE status = 'accepted' 
AND airline LIKE '%AeBal - Aerolineas de Baleares%' 
AND location LIKE '%ALL%' 
AND aircraft LIKE '%Airbus A300B4-%' 
AND comments LIKE '%ALL%' 
ORDER BY id LIMIT 0, 15

 

The query generated at your website looks ok to me.

Link to comment
Share on other sites

You must not be passing search string varibles in your paging urls... isn't it...

 

<a href='page2.php?page=2&airline_search='<?=$_GET['airline_search']?>>page 2</a>

 

In this way send all the variables in you paging links.

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.