..I have been strugling to get this part of my site working correctly even though I can't see anything wrong with my code. I am trying to search a database and display paged results. But everytime I perform a valid test expecting a few results to appear I am left with the No Matches message, so it's not a coding error as such. The code shown below is what I have for my search.php, please could someone put me out of my misery. -
<html>
-
<head>
-
<style type="text/css">
-
.page_numbers {
-
width: 600px;
-
padding: 5px 0px;
-
float:left;
-
clear:left;
-
margin:0 auto;
-
}
-
-
.page_numbers ul {
-
margin: 0 auto;
-
list-style-type: none;
-
padding: 0px;
-
text-align: center;
-
}
-
-
.page_numbers li {
-
display: inline;
-
float: left;
-
margin:1px;
-
background: #a7a7a7;
-
width:25px;
-
}
-
-
.page_numbers li.current{
-
width:50px;
-
}
-
-
.page_numbers li a {
-
background: #fff;
-
border: 1px solid #a7a7a7;
-
padding: 1px;
-
text-decoration: none;
-
color: #000;
-
font:bold 8px verdana,sans-serif;
-
display:block;
-
}
-
-
.page_numbers a.current, .page_numbers li a:hover {
-
background: #a7a7a7;
-
color: #fff;
-
}
-
</style>
-
</head>
-
<body>
-
<?php
-
-
include "connection.php";
-
-
$min_price = $_POST['min_price'];
-
$max_price = $_POST['max_price'];
-
$property_type = $_POST['type'];
-
$location = $_POST['location'];
-
$min_bedrooms = $_POST['min_beds'];
-
$keywords = $_POST['keywords'];
-
-
-
//$min_bedrooms = 2;
-
-
$webpage = basename($_SERVER['PHP_SELF']);
-
function pagination_five($total_pages,$page){
-
-
global $webpage, $min_price, $max_price, $property_type;
-
global $location, $min_bedrooms, $keywords;
-
-
$max_links = 10;
-
$h=1;
-
if($page>$max_links){
-
$h=(($h+$page)-$max_links);
-
}
-
if($page>=1){
-
$max_links = $max_links+($page-1);
-
}
-
if($max_links>$total_pages){
-
$max_links=$total_pages+1;
-
}
-
if($total_pages>1){
-
echo '<div class="page_numbers"><ul>';
-
if($page>"1"){
-
echo '<li class="current"><a href="'.$webpage.'?page=1">First</a></li>
-
<li class="current"><a href="'.$webpage.'?page='.($page-1).'">Prev</a></li>
-
';
-
}
-
-
if($total_pages!=1){
-
for ($i=$h;$i<$max_links;$i++){
-
if($i==$page){
-
echo '<li><a class="current">'.$i.'</a></li>';
-
}
-
else{
-
echo '<li><a href="'.$webpage.'?page='.$i.'">'.$i.'</a> </li>';
-
}
-
}
-
}
-
-
if(($page >="1")&&($page!=$total_pages)){
-
echo '<li class="current"><a href="'.$webpage.'?page='.($page+1).'">Next</a></li>
-
<li class="current"><a href="'.$webpage.'?page='.$total_pages.'">Last</a></li>
-
';
-
}
-
echo '</ul></div>';
-
}
-
}
-
-
$result = mysql_query("Select count(*) from search WHERE bedrooms = $min_bedrooms")
-
or die (mysql_error());
-
$numrows = mysql_fetch_row($result);
-
-
if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1);
-
$entries_per_page = 1;
-
-
$total_pages = ceil($numrows[0]/$entries_per_page);
-
$offset = (($page * $entries_per_page) - $entries_per_page);
-
-
//after we have $total_pages and $page, we can include the
-
//pagination style wherever we want on the page.
-
//so far there is no output from the script, so we could have
-
//pagination before or after the pages results
-
-
//before the results
-
-
$result = mysql_query("SELECT * FROM search WHERE (price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type' AND keywords LIKE '%$keywords%') OR
-
(price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type') ORDER BY id ASC LIMIT
-
$offset,$entries_per_page");
-
if(!$result) die(mysql_error());
-
$err = mysql_num_rows($result);
-
if($err == 0) die("No matches met your criteria.");
-
-
while($row=mysql_fetch_array($result)){
-
-
$formatted = number_format($row['price'],2);
-
-
echo "<div id=\"right\"><img src=\"".$row['image']."\"><a href=\"detail.php\">".$row['title']."</a><h4>Offers over £".$formatted."</h4><p>".$row['type'].", ".$row['bedrooms']." bedrooms</p><br /></div>\n";
-
-
}
-
-
//or after the results
-
-
pagination_five($total_pages,$page);
-
-
?>
-
</body>
-
</html>
-
7 2430
Try some simple searching first, the problem might be in the data inside your tables. Simplify this part first so that you'll know the error: -
$result = mysql_query("SELECT * FROM search WHERE (price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type' AND keywords LIKE '%$keywords%') OR
-
(price BETWEEN '$min_price' AND '$max_price' AND bedrooms >= '$min_bedrooms' AND location = '$location' AND type = '$property_type') ORDER BY id ASC LIMIT
-
$offset,$entries_per_page");
-
Atli 5,058
Recognized Expert Expert
Hi.
I agree. I can't see anything wrong with the PHP code itself so the SQL query seems to be the cause of your problem.
Have you tested it on the database?
P.S.
I've changed the title of this thread to better describe it's topic.
Using good, descriptive titles that follow the Posting Guidelines will increase your chances of getting you questions answered! Moderator
Hi.
I agree. I can't see anything wrong with the PHP code itself so the SQL query seems to be the cause of your problem.
Have you tested it on the database?
P.S.
I've changed the title of this thread to better describe it's topic.
Using good, descriptive titles that follow the Posting Guidelines will increase your chances of getting you questions answered! Moderator
Thanks for the title changeand the advice. I put some echo statements throughout my code to see what the variables were just before entering sql statements and all the variables passed should have given results but still give 'No Matches'. I have triple checked that all the names in the sql statements match that of table fields and now I am totally stuck. I really do not know what is wrong with my code at all.
Atli 5,058
Recognized Expert Expert
I thought this must be a problem with you SQL, so I copied it and re-formatted it so it could be read: -
SELECT *
-
FROM search
-
WHERE (
-
price BETWEEN '$min_price' AND '$max_price'
-
AND bedrooms >= '$min_bedrooms'
-
AND location = '$location'
-
AND type = '$property_type'
-
AND keywords LIKE '%$keywords%'
-
)
-
OR (
-
price BETWEEN '$min_price' AND '$max_price'
-
AND bedrooms >= '$min_bedrooms'
-
AND location = '$location'
-
AND type = '$property_type'
-
)
-
ORDER BY id ASC
-
LIMIT $offset,$entries_per_page
-
But, that looks all right to.
(Are you sure there is any data in the tables? :P)
Try removing the LIMIT clause, see what happens.
If that doesn't work, try reducing the search criteria until you find the problem.
Note, the ORDER BY id ASC is redundant. This is the default behavior. (as far as I know).
And I noticed a part of your code that could be optimized.
1st.
$min_price = $_POST["min_price"];
$max_price = $_POST["max_price"];
etc.
= !YUCK!
extract($_POST) ; // easy simple way of taking everything from the $_POST array and automatically generates all the variables with their respective $_POST names. The downside is that it takes all the variables in the $_POST array and automatically generates all the variables with their respective $_POST name... if you only need say one of the variables, then you're wasting memory with excessive overuse.
i.e. $min_price is already set
Thanks for the help, I eventually got the problem sorted by numbering my drop down list option values, so it must've been to do with that.
Atli 5,058
Recognized Expert Expert
And I noticed a part of your code that could be optimized.
1st.
$min_price = $_POST["min_price"];
$max_price = $_POST["max_price"];
etc.
= !YUCK!
extract($_POST) ; // easy simple way of taking everything from the $_POST array and automatically generates all the variables with their respective $_POST names. The downside is that it takes all the variables in the $_POST array and automatically generates all the variables with their respective $_POST name... if you only need say one of the variables, then you're wasting memory with excessive overuse.
i.e. $min_price is already set
Hi.
I would recommend against this. It may save you a few lines of code but you are allowing user input into your code without any validation. As well as creating potentially unused variables, as you pointed out.
From a security standpoint, you should always use the super-globals ($_POST. $_GET, etc...).
What you are suggesting is basically the same as enabling the register_global s directive, which, for security and performance reasons, is disabled by default.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Xenophobe |
last post by:
I know this isn't a MySQL forum, but my question is related to a PHP
project.
I have two tables.
table1
table2
"table1" contains 2 columns, ID and FirstName:
|
by: Noel Wood |
last post by:
Hello I keep getting a warning ...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in "name of my php file" when I run this query....
SELECT Menu_Item, Quantity
FROM restorder_item
WHERE Order_Number =58
The code I use to do it is....
$query = "select Menu_Item, Quantity from restorder_item";
$query .= " where Order_Number = ".$_REQUEST;
|
by: jaysonsch |
last post by:
Hello!
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.
Now, the problem that I am...
|
by: Federico |
last post by:
Hi everybody,
I'm evaluating the possibility of using MySQL 5.0 as a database backend
for an application we are doing and I'd like to have hardware
requirements rough estimates and/or real world experience from people
that are already running similar dimensioned database/application.
As a rought estimate the database has around 80 tables 4-5 of these are
supposed to grow up to 5.000.000 records another 30% will be in the
100.000 range...
|
by: Hemant Shah |
last post by:
Folks,
I am having problem with an application that uses static SQL,
the application basically browses through the table given start and
end key most of the time it is processed from begining to end.
The db2expln tells me that there is no Data or Index prefetch.
I am running DB2 UDB 8 on AIX 5.3, and I am using DMS tablespace on
raw logical volumes on a SAN.
| |
by: Taras_96 |
last post by:
Hi everyone,
I'm having a bit of trouble understanding the purpose of escaping
nulls, and the use of addcslashes.
Firstly, the manual states that:
"Strictly speaking, MySQL requires only that backslash and the quote
character used to quote the string in the query be escaped. This
function quotes the other characters to make them easier to read in
|
by: eholz1 |
last post by:
Hello PHP group,
Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0
running on Linux (Redhat Fedora Core 6).
All that works fine. I would like to be able to "call" a stored
procedure from a PHP program, and
run a stored procedure. I have yet to figure out the proper way to do
this. My stored procedures work fine from the mysql command line
using syntax: "call sp_min_record (101);"
|
by: thepresidentis |
last post by:
here is my problem,
i have a website that compiles concert listings for users to search for shows in their local area, i ran into a problem with returning search results due to an improper format of my query, So i formatted the query properly Thanks to steve Klein :) , and all worked fine because there was only 1 show in my data base,
I tryed to search for the show and it returned properly, and then i searched for the show with a different...
|
by: Shiriah |
last post by:
I feel that this is a rather trivial concept that I cannot quite wrap my head around to make work in PHP. I consider myself an intermediate user in SQL (both MSSQL and MySQL) and somewhat novice in PHP, but I am well versed in programming in general between multiple languages (VB/Java/Python/ColdFusion). By saying this, I'm letting you know not to be afraid to use complex terminology / concepts.
Here is what I am attempting to do:
I have...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |