le007 Posted September 28, 2007 Share Posted September 28, 2007 if ($property_type== "%"){ $sql = "SELECT * FROM `tabl` WHERE `property_type` like 'Agricultural Land' OR `property_type` like 'Business' OR `property_type` like 'Cafe/Deli' 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"; } elseif ($property_type != "%"){ $sql = "SELECT * FROM `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"; } NOT working? Anyone know a fix? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/ Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 Is it the IF statement that's not working or the query that's not working? Try putting a space after $property_type and before the == If $property_type defined? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357215 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Hi buddy thanks reply... yes the query was is ok and variable is defined. I tried that but keep getting the same: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357222 Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 When executing the query do you have: //variable may be different $res = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357226 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Ok I put that in: if ($property_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like 'Agricultural Land' OR `property_type` like 'Business' 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 ($property_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()); } but the IF statement now isnt working - its just showing ALL results if $property_type == "%", it doesnt just show agricultural land, and business which is what its meant to do... any suggestions? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357234 Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 Could you echo our $property_type before you call the IF statement? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357238 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 yeah why? I dont get it? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357243 Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 Post your code before this. Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357245 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 <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 'Agricultural Land' OR `property_type` like 'Business' 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/#findComment-357247 Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 $prop_type isn't defined. Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357251 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 $prop_type = $_REQUEST['srch_property_type']; ? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357254 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 $prop_type is defined... $prop_type = $_REQUEST['srch_property_type']; Any ideas pls? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357276 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Original problem anybody help?? IF statement not working... It doesnt just show Agricultural and Business if $prop_type eqauls % if ($prop_type == "%"){ $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like 'Agricultural Land' OR `property_type` like 'Business' 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/#findComment-357300 Share on other sites More sharing options...
sasa Posted September 28, 2007 Share Posted September 28, 2007 for debug try to echo $sql if ($prop_type == "%"){ echo $sql = "SELECT * FROM `cheap_tabl` WHERE `property_type` like 'Agricultural Land' OR `property_type` like 'Business' 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 != "%"){ echo $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/#findComment-357312 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 I did that and the correct if is being used but the results still show everything... any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357383 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 } elseif ($prop_type !== "%"){ Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357391 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Thanks for that I've included it. The !== % works at the moment. The problem is if someone clicks ALL props (%) it still doesnt just show what I want - it shows everything... anyone any ideas pls? 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/#findComment-357395 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 well tell us what shows up in properties and what you want displayed? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357402 Share on other sites More sharing options...
sasa Posted September 28, 2007 Share Posted September 28, 2007 your where part of $sql select all rovs where propert_type = 'House' and all rows where `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) doe's it what you want i think zhat you want $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"; Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357404 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Thanks for the replies - I really thought the brackets () was it! But it wasn't... basically the problem is, people have a an option to search for specific property types (houses, sites, offices, apartments, land, etc). When they click on say HOUSE it works fine, it just shows houses in the results but if they click search and dont specify a property type eg(%) EVERYTHING comes up and I only want "Sites" and "Houses" to appear in the results. (Long story but thats all I want to show) Anyone other ideas? Many thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357417 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 <?php if ($propertytype!=="house") { echo "sorry but there are no houses"; } else if ($propertytype!=="apartment") { echo "sorry but there are no apartments";?> Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357422 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 Won't work cos I have to allow the user search for all property types - its an option they must have. Its in a loop too, I just want the query to skip anything that doesnt have house or site in it! thanks again for your help - just dunno how to get this result... Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357428 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 can you post the code i cant make up code and expect it to work? Quote Link to comment https://forums.phpfreaks.com/topic/71051-if-statement/#findComment-357433 Share on other sites More sharing options...
le007 Posted September 28, 2007 Author Share Posted September 28, 2007 <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/#findComment-357439 Share on other sites More sharing options...
darkfreaks Posted September 28, 2007 Share Posted September 28, 2007 no wonder it shows everything you have it so if its set ot false it displays everything } 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/#findComment-357444 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.