le007 Posted September 28, 2007 Author Share Posted September 28, 2007 I thought that would mean if something was selected (as it wasn't just % everything) then it would show the selected only... Have you a fix pls? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357448 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 I changed it to: if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE (`property_type` like 'House' OR `property_type` like 'Site') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } else { $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } But all this does is show site and house and then all the rest after it - for some reason it has site and house as the first results and then it just continues to show everything regardless! Any thoughts? Thanks mate Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357455 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 ok explain what you want done upon it not equaling the property? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357458 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 <?php if ($propertytype!=="house") { $sql= "SELECT * FROM table VALUES (apartment,allpropertytypes notmatching house)"; } else if ($propertytype!=="apartment") { $sql= "SELECT * FROM table VALUES (house,allpropertytypes notmatching apartment)"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357462 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Yeah but how do I incorporate that into this: if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE (`property_type` like 'House' OR `property_type` like 'Site') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } else { $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } I've also figured out thats the first results page is working fine... it must be do with the 2nd page or loop? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357464 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 put back the if ($prop_type !== "%"){ Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357471 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Ok its back - did u get my pm? if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE (`property_type` like 'House' OR `property_type` like 'Site') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } elseif ($prop_type !== "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357473 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Can anyone pls help me with this thing... I've spent the last few hrs on it! Its driving me nuts! I have a paginated results page, the first page seems to be working ok, I only want House and Site to be shown in results IF there is no property type selected. If there is a property type selected then I just want that in results eg if someone clicks site and search then only site will come up. Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357482 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357489 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 Any ideas anybody? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357621 Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Share Posted September 29, 2007 instead of like try MATCH AGAINST SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('search string'); Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357625 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE MATCH(`property_type`) AGAINST ('house') OR MATCH (`property_type`) AGAINST ('site') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } elseif ($prop_type !== "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } That ok? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357630 Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Share Posted September 29, 2007 im not sure you tell me? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357631 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 "Can't find FULLTEXT index matching the column list" I was just wondering if the syntax was ok. Thanks for your help... its so SO close just dunno how to fix it. Thought someone here could. I just thought a simple if variable = "house" then do this, if not then do this etc Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357633 Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Share Posted September 29, 2007 yeah i think the fields in the database need to be text or varchar, please tell me there is a field for every property? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357634 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 They are champ, they are... I've now tried if, case and match against... it doesnt make sense to me thats it not working... Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357635 Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Share Posted September 29, 2007 maybe reading this will help http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357637 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 Ok thanks. Gunna finish for the nite - might post again tomo under a different title or something. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357638 Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Share Posted September 29, 2007 nite bud but its like saying search this property type and this property type against your database Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357640 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 Yeah but the property type is generated from a text file not the db Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357644 Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Share Posted September 29, 2007 well maybe you need to change it im not really used to using fopen, flose fread fwrite functions Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357646 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 No it is being retrieved from a db - but the file is read into the dropdown from a text file. It is from db... I dunno bud I just don't know Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357647 Share on other sites More sharing options...
teng84 Posted September 29, 2007 Share Posted September 29, 2007 let me join ! can you tell me your prob now and your recent code? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357648 Share on other sites More sharing options...
le007 Posted September 29, 2007 Author Share Posted September 29, 2007 No problem. My forum question is to do with an if statement in my search results page. I just thought a simple if variable = "house" then do this, if not then do this etc I receive information from a search page. If property type drop down box is left as "All property types" then I want "House" and "Site" results only to be shown. Property types are house, site, land, apartment, semi-detached. Else if something is selected then only show it, eg apartment The if is as follows and then I'll include the pages whole code: if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE (`property_type` like '%house%' OR `property_type` like '%site%') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } elseif ($prop_type !== "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } I've tried house and site without % too. I've also tried case and now match against. The rest of the code: <Style> #divpn{ background: yellow; width: 110px; float: left; } #divnp{ background: yellow; width: 110px; float: left; } </style> <br> <center> <img src="headimage/searchr.png" title="Search Results"> <hr width="520px" color="#650066"> <table cellspacing="0" cellpadding="10%" class="feat" width="520px" height="600px"> <tr> <td valign="top"> <font size=2 face="arial" color="#65066"> <center> <?php //define variables $border="0"; //connects to database etc. include("config.php"); //set dbtotal variable - it's the total number of rows on the MySQL table $ark = mysql_query("SELECT * FROM `cheap_tabl`") or die(mysql_error()); $dbtotal = mysql_num_rows($ark); //get variables from url $countycode = $_REQUEST['cp_county']; $townnumber = $_REQUEST['cp_town']; $minprice = $_REQUEST['minprice']; $maxprice = $_REQUEST['maxprice']; $minbeds = $_REQUEST['minbeds']; $maxbeds = $_REQUEST['maxbeds']; $prop_type = $_REQUEST['srch_property_type']; // if county is not specified then search for everything: if ($countycode == ""){ $countycode="%"; $town="%"; } if ($countycode == "%"){ $town="%"; } //find out which town is town_number $sqlcakefred = "SELECT * FROM `townsandcounties` where `countycode` like '". $countycode ."'"; $flib = mysql_query($sqlcakefred) or die(mysql_error()); $total_towns = 1; while($row = mysql_fetch_array($flib)){ $j = $j + 1; if ( $j == $townnumber ) {$town=$row['town'];$area=$row['county'];} if ( ($area == '') && ($town=='') ){ $town="%"; $area=$row['county']; } // if townnumber is 0 then they searched for all properties within a county: if ($townnumber == 0) {$county = $row['county'];} $county=$row['county']; } if ($countycode=="%"){ $county='%';} // Basically, if the page number is not specified, start with page 1 (i.e. set $page as 1), // otherwise set $page as whatever the page number is set as in the url if(!isset($_REQUEST['page'])){ $page = 1; } else { $page = $_REQUEST['page']; } //TOP SITEMAP include("sitemap2.php"); // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); //this is the split between the sitemap at the top and the start of results. add as many <BR> as you like echo "<BR>"; // start a table for query results echo "<table border='" . $border . "'>"; /* -------------------- START MAIN QUERY -------------------- */ if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE (`property_type` like '%house%' OR `property_type` like '%site%') and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } elseif ($prop_type !== "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1) ORDER BY cheap_id DESC LIMIT $from, $max_results"; $sirsql = mysql_query($sql) or die(mysql_error()); } // Perform MySQL query on only the current page number's results /* -------------------- END MAIN QUERY -------------------- */ //start the loop while($row = mysql_fetch_array($sirsql)){ $resultnum++; $resultnumber = ($max_results * ($page-1)) +$resultnum; // MAIN STRINGS $id=$row['cheap_id']; $agent=$row['agent']; $address=$row['address']; $town_city=$row['town_city']; $bedrooms=$row['bedrooms']; $area=$row['area']; $price=$row['price']; $description=$row['description']; $numberofpics=$row['number_of_images']; $property_type=$row['property_type']; // END MAIN STRINGS $numberofadditionalpics = $numberofpics - 1; // add commas to price $priceshow = preg_replace('/(?<=\d)(?=(\d\d\d)+$)/', ',', $price); // the reason for this next string is so that the sitemap knows that when you go //to vproperty.php that you were passed from viewresults.php - check the if //statement on viewproperty in sitemap2.php in order for it to make more sense $vr=1; //connect to users database and get info on the agent $sqltwo = "SELECT * FROM `users` where `login` = '$agent'"; $resulttwo = mysql_query($sqltwo) or die(mysql_error()); $rowtwo = mysql_fetch_array($resulttwo); $agencyname=$rowtwo['agencyname']; $agencyemail=$rowtwo['email']; $agencyweb=$rowtwo['web']; //if $agencyweb is missing http:// , then add it if ( (!strpos($agencyweb, "ttp://")) && ($agencyweb) ) {$agencyweb="http://".$agencyweb;} // split the description up - take only first 100 letters. then add "...." $description_short=substr($description, 0, 100) . "...."; //word wrap the description $description_short = wordwrap($description_short, 25, "\n", true); /* -------------------- START TABLE ----------------------- */ echo <<<HERE </b> <table class="resultstable"> <tr> <td style="border-bottom: 1px #650066 solid;" bgcolor="#669ACC" colspan="2" align="center"> <font color="white" face="arial" size="2"><u> <b>SEARCH RESULT #$resultnumber</b> </TD> </tr> <tr> <td valign="top" align="left" width="50%" style="padding-top:5px; padding-left: 10px;"> <b>$address</b> - $town_city, $area <br> <b>$property_type <br> <b>Bedrooms: </b></b>$bedrooms <br> <b>Asking Price:</b></b> € $priceshow <br> <br> </b>$description_short <br> <br> <b>Property #</b> $id <br> <b><font face="verdana" size="1">$agencyname</b> <br> <a href="mailto:$agencyemail">$agencyemail</a> <br> <a target="new" href="$agencyweb">$agencyweb</a> </td> <td align="center" valign="top" style="padding-top:10px;"> <p class="resultimage"> <a href="index.php?locate=viewproperty&area=$townnamez&prop=$id&srch_property_type=$prop_type&cp_county=$countycode&cp_town=$townnumber&page=$page&minprice=$min price&maxprice=$maxprice&minbeds=$minbeds&maxbeds=$maxbeds&vr=$vr"> HERE; $mainimage = "images/prop". $id . "_1.jpg"; if ( (file_exists($mainimage)) && ($numberofpics > 0) ) { echo "<img src='imgsize.php?w=188&h=140&constrain=1&img=images/prop" . $id . "_1.jpg' border='2' width='210' height='162'></a></p>";} else { echo "<img src='imgsize.php?w=188&h=140&constrain=1&img=images/noimages.jpg' border='2' width='210' height='162'></a></p>"; $numberofpics=0; } ECHO <<<HERE <font color="#650066" face="arial" size="2"> HERE; //----------------------------------------------------------------------------------------- // Say 1 photo only or tell how many additional photos, if not logged in. if(!isset($_SESSION["loggedIn"])) { if ($numberofadditionalpics == 0) { echo "<a href='index.php?locate=viewproperty&area=$townnamez&prop=$id&srch_property_type=$prop_type&cp_county=$countycode&cp_town=$townnumber&page=$page&minprice=$min price&maxprice=$maxprice&minbeds=$minbeds&maxbeds=$maxbeds&vr=$vr'><b>1 Photo Only</a></b>"; } if (($numberofadditionalpics > 0) && ($numberofpics > 0)) { echo "<a href='index.php?locate=viewproperty&area=$townnamez&prop=$id&srch_property_type=$prop_type&cp_county=$countycode&cp_town=$townnumber&page=$page&minprice=$min price&maxprice=$maxprice&minbeds=$minbeds&maxbeds=$maxbeds&vr=$vr'><b>$numberofadditionalpics Additional Photos</a></b>"; } } //----------------------------------------------------------------------------------------- // This next include box is a members box with an edit pencil and a red x for delete // this should only appear if logged in as a member, oh and if you are the uploader // of the property (correct agent) if(isset($_SESSION["loggedIn"]) && (($agent == $_SESSION["login"]) or ($_SESSION["login"] == "administrator"))){ include ("resmembox1.inc.php"); } ECHO <<<HERE </td> </tr> </table> HERE; //this is the split between each property, add as many <BR> as you like echo "<BR>"; } /* -------------------- END TABLE ----------------------- */ /* -------------------- START PAGINATION LINKS ----------------------- */ // Figure out the total number of results in DB: $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `cheap_tabl` WHERE `property_type` like '$prop_type' and `area` like '$county' and `town_city` like '$town' and `price` > ($minprice + 1) and `price` < ($maxprice + 1) and `bedrooms` > ($minbeds - 1) and `bedrooms` < ($maxbeds + 1)"),0); if ($total_results > 0) { echo "<b>TOTAL RESULTS=$total_results</b><br>"; } // ***********The No results Error************ if ($total_results == 0) { include ("no_search_results.php"); } else { // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); //show where you are if ($total_results > 0){ echo "Page $page of $total_pages [$max_results max results per page]<br>"; } // Build Page Number Hyperlinks if ($total_pages > 1){echo "<center><p class='speciallink'><b><u>Select a Page</b></u><br><br>";} // Build Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href='index.php?locate=viewresults&srch_property_type=$prop_type&cp_town=$townnumber&cp_county=$countycode&page=$prev&minprice=$minprice&maxprice=$maxprice&m inbeds=$minbeds&maxbeds=$maxbeds&vr=$vr'><font size='3'><B><<Previous</B></a> </font>"; } if ($total_pages > 1){ $lowend=$page-3; $topend=$page+3; for($i = $lowend; $i <= $topend; $i++){ if(($i>0)&&($i<($total_pages+1))){ if(($page) == $i){ echo "<font size='3'><B>$i</B></font> "; } else { echo "<a href='index.php?locate=viewresults&srch_property_type=$prop_type&cp_town=$townnumber&cp_county=$countycode&page=$i&minprice=$minprice&maxprice=$maxprice&minb eds=$minbeds&maxbeds=$maxbeds&vr=$vr'>$i</a> "; } } } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href='index.php?locate=viewresults&srch_property_type=$prop_type&cp_town=$townnumber&cp_county=$countycode&page=$next&minprice=$minprice&maxprice=$maxprice&m inbeds=$minbeds&maxbeds=$maxbeds&vr=$vr'><font size='3'><b>Next>></b></font></a>"; } //end of pagination echo "</center>"; /* -------------------- END PAGINATION LINKS ----------------------- */ } // end of MIDDLE. Close off table echo "</table>"; ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357650 Share on other sites More sharing options...
teng84 Posted September 29, 2007 Share Posted September 29, 2007 switch (yourvariable){ case 'all': $query = 'where property_type in ("House","Site")'; break; case 'house': $query='where property_type="House"'; break; case: //etccc... break; default: //use this if you have a default value break; } $query = "SELECT * FROM `cheap_tabl`".$query; try Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/page/2/#findComment-357652 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.