If statement problem...

Discussion in 'PHP' started by le007, Sep 28, 2007.

  1. #1
    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());

    }

    For some reason if $prop_type eqauls % then it STILL shows everything. It doesn't just show House and Site results... any ideas pls? Very annoying...
     
    le007, Sep 28, 2007 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    Use can USE THE bb tags

    <?php 
    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());
    }
    ?>
    
    PHP:
     
    nabil_kadimi, Sep 28, 2007 IP
  3. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #3
    It looks like your problem is located somewhere else... maybe a bad use of the $prop_type variable
     
    nabil_kadimi, Sep 28, 2007 IP
  4. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    <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>&lt;&lt;Previous</B></a>&nbsp;</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>&nbsp;";
    		} 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>&nbsp;";
    		}
    	}
    		}
    }
    // 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&gt;&gt;</b></font></a>";
    }
    
    
    
    //end of pagination
    echo "</center>";  
    /*    -------------------- END PAGINATION LINKS ----------------------- */
    }
    // end of MIDDLE. Close off table
    echo "</table>";
    
    
    ?>
    
    
    </table>
    
    PHP:
     
    le007, Sep 28, 2007 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Anyone any ideas pls? Can't get it right
     
    le007, Sep 28, 2007 IP
  6. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    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());
    Code (markup):
     
    le007, Sep 28, 2007 IP
  7. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #7
    I tried brackets (`property_type` like 'House' OR `property_type` like 'Site') but it didnt work... any ideas anyone?

    Thanks
     
    le007, Sep 28, 2007 IP
  8. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #8
    } elseif ($prop_type !== "%"){
    Code (markup):
    will you try

    } else if ($prop_type != "%"){
    Code (markup):
     
    PinoyIto, Sep 28, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    The percent sign (as value) can only be a string, so it's okay using the double equal sign (not identical) in this case cause there's no chance it can be another type.

    However, he had this in his first code and it didn't seem to work either.
     
    nico_swd, Sep 28, 2007 IP
  10. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #10
    I tried that.

    I'm now here:

    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());
    }

    Its very close - when I get it fixed, I'll post how I managed to do it!
     
    le007, Sep 28, 2007 IP
  11. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #11
    In my opinion it's not the if clause but in the query statement, that is the reason why you're not getting the result you want to get.
     
    PinoyIto, Sep 28, 2007 IP
  12. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #12
    Sorry I don't get you -
     
    le007, Sep 28, 2007 IP