Jump to content


Photo

help with search form result


  • Please log in to reply
5 replies to this topic

#1 saini

saini
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 June 2006 - 09:27 PM

I have a search form that searches 2 tables. I am not getting results correctly.
The form is at zetourz.com/search.php
If I just select Country and city, it should give out all rows with that country & city, but I am somehow not getting that as expected.
The query I have is
mysql_select_db($database_tour, $tour);
$query_rsSearch = sprintf("SELECT tour.*, hotdeals.* FROM (tour LEFT JOIN hotdeals ON hotdeals.tour_hotdeals=tour.id_tour) WHERE (country_tour = %s AND city_tour = %s) OR name_tour LIKE %s OR days_tour>=%s OR days_tour<=%s OR type_tour LIKE %s OR type2_tour LIKE %s OR type3_tour LIKE %s OR type4_tour LIKE %s OR start_hotdeals>=%s OR end_hotdeals<=%s ORDER BY tindex_tour ASC"

Please help find the problem.

Thanks,
saini
! There's always something that we don't even know, that we don't know!
[a href="http://www.gigadesignonline.ru" target="_blank"]создание сайта[/a]

#2 Wildbug

Wildbug
  • Members
  • PipPipPip
  • Advanced Member
  • 1,149 posts

Posted 15 June 2006 - 02:56 PM

[!--quoteo(post=383990:date=Jun 14 2006, 05:27 PM:name=saini)--][div class=\'quotetop\']QUOTE(saini @ Jun 14 2006, 05:27 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
...
mysql_select_db($database_tour, $tour);
$query_rsSearch = sprintf("SELECT tour.*, hotdeals.* FROM (tour LEFT JOIN hotdeals ON hotdeals.tour_hotdeals=tour.id_tour) WHERE (country_tour = %s AND city_tour = %s) OR name_tour LIKE %s OR days_tour>=%s OR days_tour<=%s OR type_tour LIKE %s OR type2_tour LIKE %s OR type3_tour LIKE %s OR type4_tour LIKE %s OR start_hotdeals>=%s OR end_hotdeals<=%s ORDER BY tindex_tour ASC"
[/quote]

Can you post the rest of the sprintf() line?
Twice a day my clock works PERFECTLY!  I can't figure out what's wrong with it.

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 15 June 2006 - 05:13 PM

Maybe you're missing some grouping parentheses... also, why the derived table?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 saini

saini
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 June 2006 - 07:47 PM

Here is the complete code:
$colname_rsSearch = "-1";
if (isset($_POST['country'])) {
$colname_rsSearch = (get_magic_quotes_gpc()) ? $_POST['country'] : addslashes($_POST['country']);
}
$colname9_rsSearch = "-1";
if (isset($_POST['startdate'])) {
$colname9_rsSearch = (get_magic_quotes_gpc()) ? $_POST['startdate'] : addslashes($_POST['startdate']);
}
$colname10_rsSearch = "-1";
if (isset($_POST['enddate'])) {
$colname10_rsSearch = (get_magic_quotes_gpc()) ? $_POST['enddate'] : addslashes($_POST['enddate']);
}
$colname6_rsSearch = "-1";
if (isset($_POST['tourtype'])) {
$colname6_rsSearch = (get_magic_quotes_gpc()) ? $_POST['tourtype'] : addslashes($_POST['tourtype']);
}
$colname7_rsSearch = "-1";
if (isset($_POST['tourtype'])) {
$colname7_rsSearch = (get_magic_quotes_gpc()) ? $_POST['tourtype'] : addslashes($_POST['tourtype']);
}
$colname8_rsSearch = "-1";
if (isset($_POST['tourtype'])) {
$colname8_rsSearch = (get_magic_quotes_gpc()) ? $_POST['tourtype'] : addslashes($_POST['tourtype']);
}
$colname5_rsSearch = "-1";
if (isset($_POST['tourtype'])) {
$colname5_rsSearch = (get_magic_quotes_gpc()) ? $_POST['tourtype'] : addslashes($_POST['tourtype']);
}
$colname3_rsSearch = "-1";
if (isset($_POST['mindays'])) {
$colname3_rsSearch = (get_magic_quotes_gpc()) ? $_POST['mindays'] : addslashes($_POST['mindays']);
}
$colname4_rsSearch = "-1";
if (isset($_POST['maxdays'])) {
$colname4_rsSearch = (get_magic_quotes_gpc()) ? $_POST['maxdays'] : addslashes($_POST['maxdays']);
}
$colname1_rsSearch = "-1";
if (isset($_POST['city'])) {
$colname1_rsSearch = (get_magic_quotes_gpc()) ? $_POST['city'] : addslashes($_POST['city']);
}
mysql_select_db($database_tour, $tour);
$query_rsSearch = sprintf("SELECT tour.*, hotdeals.* FROM (tour LEFT JOIN hotdeals ON hotdeals.tour_hotdeals=tour.id_tour) WHERE (country_tour = %s AND city_tour = %s) OR days_tour>=%s OR days_tour<=%s OR (type_tour LIKE %s OR type2_tour LIKE %s OR type3_tour LIKE %s OR type4_tour LIKE %s) OR start_hotdeals>=%s OR end_hotdeals<=%s ORDER BY tindex_tour ASC", GetSQLValueString($colname_rsSearch, "text"),GetSQLValueString($colname1_rsSearch, "int"),GetSQLValueString($colname3_rsSearch, "text"),GetSQLValueString($colname4_rsSearch, "text"),GetSQLValueString($colname5_rsSearch, "text"),GetSQLValueString($colname6_rsSearch, "text"),GetSQLValueString($colname7_rsSearch, "text"),GetSQLValueString($colname8_rsSearch, "date"),GetSQLValueString($colname9_rsSearch, "int"),GetSQLValueString($colname10_rsSearch, "text"));
$query_limit_rsSearch = sprintf("%s LIMIT %d, %d", $query_rsSearch, $startRow_rsSearch, $maxRows_rsSearch);
$rsSearch = mysql_query($query_limit_rsSearch, $tour) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);

The first table named tour has tour description. The second table named hotdeals has dates that are associated with the tour. If you click any tour on site, the description is on the page. On the right hand side, you can see a table with dates, this is what I have in hotdeals table.

I may be missing parenthesis, but that's where I always get the problems.
Thanks,
saini
! There's always something that we don't even know, that we don't know!
[a href="http://www.gigadesignonline.ru" target="_blank"]создание сайта[/a]

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 June 2006 - 07:33 AM

Man, that code ain't pretty... but regardless, I still don't know what you mean by "unexpected results"... does each of the OR conditions alone produce the correct results?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 saini

saini
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 June 2006 - 09:28 PM

What's not pretty in that code?
Ok, I found out that DW went crazy and changed string type. I corrected the string type but the same result.
Anyway, i changed post to get method to visually control everything. I am on my way and getting results. Hope I will get it over and change get to post again.
Thanks anyway.
Thanks,
saini
! There's always something that we don't even know, that we don't know!
[a href="http://www.gigadesignonline.ru" target="_blank"]создание сайта[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users