Page 1 of 1

problem with search

Posted: Fri Feb 02, 2007 1:19 pm
by bxm_3
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


for the webpage 

http://www.assists.org.uk/penpal_simple1_searchs.html

I get results on the subsequent page

the sql I am using is shown below

[syntax="sql"]select * from PENPAL where YEAROFBIRTH >'$y2' and YEAROFBIRTH<'$y1'or DAYOFBIRTH<='$d1' and '$m1' =MONTHOFBIRTH and '$y1'=YEAROFBIRTH or MONTHOFBIRTH <'$m1' and '$y1'=YEAROFBIRTH or DAYOFBIRTH>='$d2' and '$m2' =MONTHOFBIRTH and '$y2'=YEAROFBIRTH or MONTHOFBIRTH >'$m2' and '$y2'=YEAROFBIRTH LIMIT 0,10
If on http://www.assists.org.uk/penpal_simple1_searchs.html I add the ages 10 and 17 I get ID 4, while if I add the ages 10 and 16. I do not get ID 4. I find with the second greater age on the http://www.assists.org.uk/penpal_simple1_searchs.html, if the year is equal to the second date of birth calculated and the month of that year is 10,11,12(October, November,December) the penpal is not printed out, do I make the second month 01,02,03,04,05,06,07,08,09, rather than 1,2,3,4,5,6,7.8,9.

Will that have an effect?


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: problem with search

Posted: Sat Feb 03, 2007 1:26 pm
by califdon

Code: Select all

select * from PENPAL where YEAROFBIRTH >'$y2' and YEAROFBIRTH<'$y1'or DAYOFBIRTH<='$d1' and '$m1' =MONTHOFBIRTH and '$y1'=YEAROFBIRTH or MONTHOFBIRTH <'$m1' and '$y1'=YEAROFBIRTH or DAYOFBIRTH>='$d2' and '$m2' =MONTHOFBIRTH and '$y2'=YEAROFBIRTH or MONTHOFBIRTH >'$m2' and '$y2'=YEAROFBIRTH LIMIT 0,10
First of all, it's risky to mix ANDs and ORs in a long boolean statement like that, without parentheses. The results are often quite different from what you think you have asked for.

Next, I'm not clear on what you are trying to do and what your variables represent. Presumably you are trying to search for a date between two dates. Ordinarily, I would expect the earlier dates to be $y1 and $m1, but your logic above is just the reverse. You seem to be asking for where the year of birth is greater than the second (presumably later) date and earlier than the first date, etc.

Finally, you could greatly simplify this whole process by combining the year, month (and day, if you wish) of each date into a real date format, using mktime() and then using regular date comparisons.