473,490 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to search records by date

3 New Member
Hi

I am trying to build a search function on php its working fine but as there are lot of records on database from past it runs very slow. is there way to make it so it only looks up from today's date to future dates nothing in past search term i am using is here

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM diary WHERE $searchterm LIKE '%$search%' LIMIT 0, 50 ";
  2. $results = mysql_query( $query );
Nov 2 '10 #1
9 2774
NeoPa
32,556 Recognized Expert Moderator MVP
As this is a MySQL question (not PHP related I'm afraid) I will move it across.

The simple answer is that the WHERE clause should handle that quite easily for you, but I'm not very familiar with that dialect of SQL so I cannot help further.
Nov 2 '10 #2
Oralloy
988 Recognized Expert Contributor
goodonya,

You need to insert a condition in your WHERE clause, which checks against today's date.

Using your code as a basis, it should look something like this:
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM diary WHERE ($searchterm LIKE '%$search%') AND (diary.dateField >= CURDATE()) LIMIT 0, 50 "; 
  2. $results = mysql_query( $query ); 
Nov 3 '10 #3
goodonya
3 New Member
Hi Oralloy

thank you for replay. I copied code that you put at top and doesn't work for some reason for me it just fails and comes with login screen to database in small window instead of result to search. do you something that i have put wrong ?

Raj
Nov 4 '10 #4
Oralloy
988 Recognized Expert Contributor
good afternoon goodonya,

I thought you'd just comment out the line where you build the query and insert mine in its place.

If you go back and re-run your code, does it behave like it used to? I'm asking, because I can't think of a single reason why simply changing the qurey would require you to login again.

Anyway, give it a quick try and tell me what you find out. I'm about to leave for three days, so let's get it solved as quick as we can.
Nov 4 '10 #5
Oralloy
988 Recognized Expert Contributor
goodonya,

I wasn't thinking. Did you replace the string "dateField" in my query with the name of the date field from the table?

Cheers!
Nov 4 '10 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Goodonya:
do you something that i have put wrong ?
Essentially, we can't answer this as we can't see what you've done. You need to post what you have used so that we have something to work with. I say we, but in reality Oralloy is taking the brunt of this. He cannot help you easily unless you post what you're doing.
Nov 5 '10 #7
goodonya
3 New Member
Hey Guys

First of all sorry for taking long to get back.

Oralloy - Thank you very much for your help it was me being dumb as I mentioned I am new to php but i didnt change "dateField" to my database date table and thats what was creating the problem. so all sorted now all working fine so once again thank you for your help.

NeoPa - I am sorry but this is my first time on Fourms so not sure how it works so just trying to get head round but should keep your tips in mind for next questions and try to provide full details so can be easier for person to answer. Thank you

Cheers
Nov 5 '10 #8
NeoPa
32,556 Recognized Expert Moderator MVP
That's a fine attitude Goodonya, but remember you will benefit as much, if not more so, than we will when you provide the required information (in your future questions). What's good for the goose is good for the gander ;-)
Nov 6 '10 #9
Oralloy
988 Recognized Expert Contributor
goodonya,

I'm glad you got your problem sorted out.

Good luck with the rest of the project!
Nov 8 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
4116
by: R. Rajesh Jeba Anbiah | last post by:
Q: Is PHP search engine friendly? Q: Will search engine spiders crawl my PHP pages? A: Spiders should crawl anything provided they're accessible. Since, nowadays most of the websites are been...
1
8698
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
5
2953
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
3
4183
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been...
39
4351
by: Noticedtrends | last post by:
Can inference search-engines narrow-down the number of often irrelevant results, by using specific keywords; for the purpose of discerning emerging social & business trends? For example, if...
28
3124
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
4
2157
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
1
7509
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
0
2428
by: passion | last post by:
"Specialized Search Engines" along with Google Search Capability (2 in 1): http://specialized-search-engines.blogspot.com/ Billions of websites are available on the web and plenty of extremely...
3
1808
by: Raj G | last post by:
Hello I have got a search function on database. People can search and once they got what they want they can edit the results to what they want but i want to do is when they finished editing i want...
0
6967
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...
0
7142
Oralloy
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,...
0
7181
jinu1996
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...
0
5445
agi2029
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,...
0
4565
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...
0
3078
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...
0
1383
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 ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.