davieboy Posted March 8, 2007 Share Posted March 8, 2007 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 https://forums.phpfreaks.com/topic/41755-site-search-woes/ Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 Change everywhere if (isset($_GET['$airline_search'])){ format to : if (isset($_GET['airline_search'])){ remove $from withing array variable name Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202410 Share on other sites More sharing options...
davieboy Posted March 8, 2007 Author Share Posted March 8, 2007 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 https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202413 Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 You are using 'post' in your html form, change it to 'get' method or change your variable to use $_POST instead of $_GET Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202419 Share on other sites More sharing options...
davieboy Posted March 8, 2007 Author Share Posted March 8, 2007 have changed the form to method = get still not having any luck though .... david (ps: realy do appreciate the help) Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202423 Share on other sites More sharing options...
davieboy Posted March 8, 2007 Author Share Posted March 8, 2007 the url is now http://www.saphotography.co.uk/search_results2.php?aircraft=Airbus&airline=&airport=&keywords=&limit=20&submit=Search would it be better using 'post'? Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202424 Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 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 https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202429 Share on other sites More sharing options...
davieboy Posted March 8, 2007 Author Share Posted March 8, 2007 i think i have got it this idiot was using the wrong 'variables' from the url duh! Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202437 Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 :o Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202442 Share on other sites More sharing options...
davieboy Posted March 8, 2007 Author Share Posted March 8, 2007 ok i do still have an issue when u search for 'boeing' it gives 25 results. on the second page, it then gives other aircraft that are not boeing... any idea why Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202449 Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 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 https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202453 Share on other sites More sharing options...
davieboy Posted March 8, 2007 Author Share Posted March 8, 2007 hmm ok looks like it has to be the 'get' method as it works with that and not with the post] thanks fort he help skali Link to comment https://forums.phpfreaks.com/topic/41755-site-search-woes/#findComment-202454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.