LeadingWebDev Posted February 18, 2010 Share Posted February 18, 2010 hi all. i help, but now i need help I have a search form for real estate, every thing work well, except floors that works, but not completely. i got to construct query if var so $query .="..."; constructed and works. The trouble is: floor -> <option value="0">Ground</option> ONLY when $floor=0 i dont get any result, but the query success. else if select 1+ im getting results as needed.=) Echoed $floor, got floor: 0 - works. tried same query in SQLyog -> works well with 0. take a look: // QUERY CONSTRUCTOR BEGIN $sqlRequest = "SELECT * FROM `sell_estate` WHERE `estate_type` = '$estate_type' AND `region` = '$region'"; //Constructing proper query part for floors if($from_floor && $to_floor) { if($from_floor == 0 || $to_floor == 0) { if($from_floor == 0 && $to_floor == 0) { $sqlRequest .=" AND floor BETWEEN '0' AND '0'"; } elseif($from_floor == 0 && $to_floor > 0) { $sqlRequest .=" AND floor BETWEEN '0' AND '$to_floor'"; } elseif($from_floor > 0 && $to_floor == 0) { echo "max floor cant be lower than min floor"; } } else { $sqlRequest .=" AND floor BETWEEN '$from_floor' AND '$to_floor'"; } }else{ if($from_floor && !$to_floor) { $sqlRequest .=" AND floor >= '$from_floor'"; } elseif($to_floor && !$from_floor) { $sqlRequest .=" AND floor <= '$to_floor'"; } } //End Constructing proper query part for floors //Query ends with sorting by ad Post Date DESCEND. $sqlRequest .=" ORDER BY `post_date` DESC"; // QUERY CONSTRUCTOR END Link to comment https://forums.phpfreaks.com/topic/192502-sql-query-by-php-trouble/ Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Author Share Posted February 18, 2010 anyone? Bump? it was looking before like that //Constructing proper query for floors if($from_floor && $to_floor) { if($to_floor > $from_floor) { echo "Max floor cant be lower than min floor."; }else{ $sqlRequest .=" AND floor BETWEEN '$from_floor' AND '$to_floor'"; { }else{ if($from_floor && !$to_floor) { $sqlRequest .=" AND floor >= '$from_floor'"; } elseif($to_floor && !$from_floor) { $sqlRequest .=" AND floor <= '$to_floor'"; } } //End Constructing proper query for floors Link to comment https://forums.phpfreaks.com/topic/192502-sql-query-by-php-trouble/#findComment-1014272 Share on other sites More sharing options...
sader Posted February 18, 2010 Share Posted February 18, 2010 just do this //incase u are not sure that u have these var's as numbers $from_floor = intval($from_floor ); $to_floor = intval($to_floor ); $sqlRequest = "SELECT * FROM `sell_estate` WHERE `estate_type` = '$estate_type' AND `region` = '$region'"; $sqlRequest .=" AND floor BETWEEN $from_floor AND $to_floor"; btw u never go inside this if "if($from_floor == 0 || $to_floor == 0)" because u are asking opposite thing above by this "if($from_floor && $to_floor)" <= so when $from_floor=0 and $to_floor=0 it will never be interpretated as TRUE Link to comment https://forums.phpfreaks.com/topic/192502-sql-query-by-php-trouble/#findComment-1014276 Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Author Share Posted February 18, 2010 alright. NOT SOLVED yet =) lets give it a 1 more try... Link to comment https://forums.phpfreaks.com/topic/192502-sql-query-by-php-trouble/#findComment-1014364 Share on other sites More sharing options...
sader Posted February 18, 2010 Share Posted February 18, 2010 How your code looks now? Hmm maybe changing query a bit would help "AND (floor BETWEEN '0' AND '0')"; Link to comment https://forums.phpfreaks.com/topic/192502-sql-query-by-php-trouble/#findComment-1014368 Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Author Share Posted February 18, 2010 unsuccess. The problem itself is in '0' that going to the query, any other INTs the script hits no problem, and giving the result when it hits '0' -> Query Success, no errors appear. looks now like //Constructing proper query for floors $from_floor = intval($from_floor); $to_floor = intval($to_floor); if($from_floor && $to_floor) { $sqlRequest .=" AND (floor BETWEEN '$from_floor' AND '$to_floor')"; }else{ if($from_floor && !$to_floor) { $sqlRequest .=" AND floor >= '$from_floor'"; } elseif($to_floor && !$from_floor) { $sqlRequest .=" AND floor <= '$to_floor'"; } } //End Constructing proper query for floors i also added few lines under... echo "$from_floor and up to $to_floor"; i see "0 and up to 6", but the query... i also tried to query in SQLyog(if u know), "SELECT * FROM `sell_estate` WHERE `floor` BETWEEN '0' AND '4'" and im getting results... so something wrong, maybe php :/ just echoed $sqlRequest: SELECT * FROM `sell_estate` WHERE `estate_type` = '2' AND `region` = '9' AND floor <= '4' AND rooms BETWEEN '1' AND '2.5' AND estate_size BETWEEN '100' AND '140' AND price <= '1000000' AND currency = 'USD' ORDER BY `post_date` DESC so we see, when i check floor 0, it is coming blank/unavaible, so here is a bug, as i see. now i will try something. ) Link to comment https://forums.phpfreaks.com/topic/192502-sql-query-by-php-trouble/#findComment-1014379 Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Author Share Posted February 18, 2010 Solved. figured it out, the problem caused by estate_size constructor, that give -> 'WHERE estate_size <=' and then query got nothing. thanks everybody. Link to comment https://forums.phpfreaks.com/topic/192502-sql-query-by-php-trouble/#findComment-1014397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.