Dear all,

What I am trying to do is as follows:

(1) all properties result readily displayed in webpage ; and

(2) property search tool (location, price & type) works as usual (search form already done) .

For example, when I go to my property webpage, I can see display of property list straight away. Then , I might want to use my property search tool to narrow down my search.

I tried to amend the code but it's either I get only (1) or (2) , but never both. Can someone please help ?

<?php 
//I USED YOUR CONNECTION BUT I PREFER YOU GET FAMILIER WITH PDO 
$con = mysql_connect('localhost', 'root', ''); 
if (!$con) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("a_database", $con); 



//  When i use this code I will get (2)  i.e. property search tool (location, price & type) works as usual  (search form already done) .

/*
$gType = isset($_GET['type']) ? $_GET['type'] : 'ALL'; 
$gLocation = isset($_GET['location']) ? $_GET['location'] : 'ALL'; 
$gPrice = isset($_GET['price']) ? $_GET['price'] : 'ALL'; 
$gHref="ContactUs_OurTeam(2).html#"; 
*/


//  When i use this code I will get (1) i.e. all properties result readily displayed in webpage
$gType = 'ALL'; 
$gLocation = 'ALL'; 
$gPrice = 'ALL'; 
$gHref="ContactUs_OurTeam(2).html#"; 



//GOT RID OF ALL THE IF CONDITIONS. IF THE VALUES ARE NOT EQUAL TO 'ALL', USE THEM IN THE QUERY 

$subQuery = array(); 

if($gType <> 'ALL') 
	$subQuery[] = 'type = \''.$gType.'\'';     
if($gLocation <> 'ALL') $subQuery[] = 'location = \''.$gLocation.'\'';
if($gPrice <> 'ALL') $subQuery[] = 'price = \''.$gPrice.'\''; /* ****FIRST BUG IN YOUR CODE***** IN YOUR CODE YOU DONT CONSIDER THE FILTERS WHEN GETTING THE TOTAL RECORDS FOR THE PAGINATION, BUT IN THE ACTUAL DISPLAY QUERY YOU CONSIDER ABOUT THE FILTERS. CONSIDER BELOW SCENARIO, PROPERTY -------- Type Price1 SOMETHING 100 SOMETHING 200 SOMETHING 300 LETS SAY YOU WANT ALL THE PROPERTIES WHICH PRICE EQUAL 400. THIS WILL RETURN 0 RECODS RIGHT. BUT SINCE YOUR TOTAL RECORDS QUERY WILL ALWAYS RETURN THE TOTAL NO OF RECODS IN THE TABLE IT WILL RETURN 3. THATS WHY YOU ALWAYS GET THE PAGINATION PAGES EVEN THOUGH YOU DONT HAVE ANY VALUES RELEVENT TO YOUR QUERY. */ $sql = "SELECT count(*) FROM property"; if(count($subQuery) > 0) $sql .= ' WHERE '.implode('AND ', $subQuery); $result = mysql_query($sql,$con) or trigger_error("SQL",E_USER_ERROR); $r=mysql_fetch_row($result); $numrows = $r[0]; $rowsperpage = 3; $totalpages = ceil($numrows/$rowsperpage); $currentpage = isset($_GET['currentpage']) ? $_GET['currentpage'] : 1;
$offset = ($currentpage - 1) * $rowsperpage; $centerPages = ""; $paginationDisplay = ""; //SIMPLYFIED YOUR CODE JUST INTO ONE FOR LOOP for($page = 1; $page <= $totalpages; $page++) { if ($page == $currentpage) $centerPages .= '&nbsp; <span class="pagNumActive">'.$page.'</span>'; else /*$centerPages .= '&nbsp; <a href="test.php?currentpage='.$page.'&type='.$gType.'&location='.$gLocation.'&price='.$gPrice.'">'.$page.'</a>'; */ $centerPages .= '&nbsp; <a href="javascript:ajaxFunction('.$page.');">'.$page.'</a>'; /*$centerPages .= '&nbsp; <a href="akmal.html?currentpage='.$page.'&type='.$gType.'&location='.$gLocation.'&price='.$gPrice.'">'.$page.'</a>';*/ } /* ****SECOND BUG IN YOUR CODE***** IF YOU CHECK YOUR CODE YOU`LL HAVE THIS IF CONDITION AS, if ($totalpages != "1") WHY USE DOUBLE CODE FOR 1? IT`S A INTERGER NOT A STRING.
*/ if ($totalpages != 1) { $paginationDisplay .= 'Page <strong>' . $currentpage . '</strong> of ' . $totalpages. '&nbsp; &nbsp; &nbsp; '; // instead of $pn insert $currentpage /* ****THIRD BUG IN YOUR CODE***** IN YOUR CODE YOU USE $_SERVER['REQUEST_URI'] AS THE HREF VALUE. WHY? JUST USE THE FILENAME DIRECTLY. AND ALSO I SEE YOU HAVE USED, <a href="'.$_SERVER['REQUEST_URI'].'&currentpage='.$add1.'&gType'.$gType.'&gLocation'.$gLocation.'&gPrice'.$gPrice.'"> LOOK AT THE GET VARIABLES. 1. THEY ARE SHOULD CHANGE AS, - gType SHOULD BE type - gLocation SHOULD BE location - gPrice SHOULD BE price 2. WHERE IS THE EQUAL (=) SIGN AFTER EACH GET VARIABLE? */ if ($currentpage != 1) { $previous = $currentpage - 1;
/*$paginationDisplay .= '&nbsp;<a href="test.php?currentpage='.$previous.'&type='.$gType.'&location='.$gLocation.'&price='.$gPrice.'"> Back</a>';*/ $paginationDisplay .= '&nbsp;<a href="javascript:ajaxFunction('.$previous.');"> Back</a>'; /*$paginationDisplay .= '&nbsp;<a href="akmal.html?currentpage='.$previous.'&type='.$gType.'&location='.$gLocation.'&price='.$gPrice.'"> Back</a>';*/ } $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; if ($currentpage != $totalpages) { $nextPage = $currentpage + 1; /*$paginationDisplay .= '&nbsp;<a href="test.php?currentpage='.$nextPage.'&type='.$gType.'&location='.$gLocation.'&price='.$gPrice.'"> Next</a>';*/ $paginationDisplay .= '&nbsp;<a href="javascript:ajaxFunction('.$nextPage.');"> Next</a>'; /*$paginationDisplay .= '&nbsp;<a href="akmal.html?currentpage='.$nextPage.'&type='.$gType.'&location='.$gLocation.'&price='.$gPrice.'"> Next</a>';*/ } } if($numrows == 0) echo 'No Records found'; else { ?> <!--<br> current page: <?php echo $currentpage; ?> <br> ---> <div style="margin-left:64px; margin-right:64px;"> <br><h2>Total Properties: <?php echo $numrows ; ?></h2></br> </div> <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div> <div style="margin-left:64px; margin-right:64px;"> <?php $sql = 'SELECT Type,Price1,Location FROM property'; if(count($subQuery) > 0) $sql .= ' WHERE '.implode('AND ', $subQuery); $sql .= ' LIMIT '.$offset.','.$rowsperpage; $result = mysql_query($sql); ?> <!----call for property table style.css----> <style type="text/css"> <!-- @import url("style.css"); --> </style> <!----end of call for property style.css----> <table id="box-table-a" > <thead> <tr> <th scope="col">Type</th> <th scope="col">Price</th> <th scope="col">Location</th> </tr> </thead> <?php while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><a href='$gHref'>" . $row['Type'] . "</a></td>"; echo "<td>" . $row['Price1'] . "</td>"; echo "<td>" . $row['Location'] . "</td>"; echo "</tr>"; } ?> <!--<br></table></br>--> </table> </div> <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div> <?php } ?> <html> <style type="text/css"> .pagNumActive { color: #000; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:link { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:visited { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:hover { color: #000; text-decoration: none; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:active { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } h2{ position:absolute; top:50px; left:550px; font-size:15px; font-weight:normal; } </style> </html>

    snippet from my html :

    <!DOCTYPE html>
    <html lang="en">
        <head>
    
        <title>Welcome To STAMC</title>
    
    <!--------------------------------------AJAX REQUEST FOR SEARCH TOOL CODE FUNCTION STARTS HERE-------------------------------------------->
    
    <script type="text/javascript"> 
    	function ajaxFunction(p){
    		var ajaxRequest;  // The variable that makes Ajax possible!
    
    		try{
    			// Opera 8.0+, Firefox, Safari
    			ajaxRequest = new XMLHttpRequest();
    		} catch (e){
    			// Internet Explorer Browsers
    			try{
    				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    			} catch (e) {
    				try{
    					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    				} catch (e){
    					// Something went wrong
    					alert("Your browser broke!");
    					return false;
    				}
    			}
    		}
    		// Create a function that will receive data sent from the server
    		ajaxRequest.onreadystatechange = function(){      // onreadystatechange stores a function
    			if(ajaxRequest.readyState == 4){                // when readyState is four means response is complete and we can get our data
    				var ajaxDisplay = document.getElementById('ajaxDiv');  // update without reload entire page
    				ajaxDisplay.innerHTML = ajaxRequest.responseText;
    			}
    		}
    		var type = document.getElementById('type').value;  // get value from HTML input
    		var location = document.getElementById('location').value;
    		var price = document.getElementById('price').value;
    
    		var queryString = "?type="+type+"&location="+location+"&price="+price+"&currentpage="+p;   // query string to pass information from HTML to PHP script
    		ajaxRequest.open("GET","getlocationxyz.php" + queryString,true);    // sending request using open method. again,  the problem could be here
    		ajaxRequest.send(null); 	  // send request to server
    	}
    </script> 
    
    <!--------------------------------------------------Style here------------------------------------------------------------>
    
    <style>
    
    		body{
    			background:#ffffff;
    			font-family:Arial;
    	}
    		span.language{
    			position:fixed;
    			font-family:Arial;
    			left:0px;
    			top:0px;
    			background:#000;
    			width:100%;
    			font-size:12px;
    			line-height:30px;   
    			text-align:right;
    			height:30px;      
    			-moz-box-shadow:-1px 0px 10px #000;
    			-webkit-box-shadow:-1px 0px 10px #000;
    			box-shadow:-1px 0px 10px #000;
    	}
    		span.language a{
    			color:#aaa;
    			text-transform:uppercase;
    			text-decoration:none;
    			margin-left:40px;				
    	}	
    		span.language a:hover{
    			color:#ddd;
    	}
    		span.reference{
    			position:absolute;
    			font-family:Arial;
    			left:0px;
    			top:900px;
    			background:#ffa500;
    			width:100%;
    			font-size:12px;
    			line-height:20px;
    			text-align:right;
    			height:20px;
    			-moz-box-shadow:-1px 0px 10px #000;
    			-webkit-box-shadow:-1px 0px 10px #000;
    			box-shadow:-1px 0px 10px #ff0000;
    	}			
    		span.reference a{
    			color:#000;
    			text-transform:uppercase;
    			text-decoration:none;
    			margin-right:10px;			
    	}			
    		span.reference a:hover{
    			color:#ff0000;
    	}
    		ul.sdt_menu{
    			margin-top:90px;
    	}
    		.small_img img{              
    			position:absolute;
    			top:40px;
    			left:0px;
    			z-index:-1;               
    	}			
    		.rectangle img{              
    			position:absolute;
    			top:210px;
    			left:846px;
    			z-index:-1;               
    	}
    		h3{
    			position: absolute;
    			top:200px;
    			left:850px;
    			font-size:15px;
    			font-weight:normal;
    
    
    	}
    		h4{
    			position:absolute;
    			top:250px;
    			right:530px;
    			font-size:15px;
    			font-weight:normal;
    	}	 
    		.content1{
    			position: absolute;
    			left:800px;
    			color:#777;
    			font:12px/1.4 "helvetica neue",arial,sans-serif;
    			width:520px;
    			margin:400px auto;
    	}
    
        #galleria{height:320px}
    
    </style>
    
    <!------------------------------------------------ load jQuery ---------------------------------------------------------->
        <script src="jquery.min1.js"></script>
    
    <!------------------------------------- load Galleria --------------------------------------------------------------------->
        <script src="galleria-1.2.6.min.js"></script>
    
    </head>
    
    <!------------------------------------- Property search here --------------------------------------------------------------------->
    <body onload="javascript:ajaxFunction(1);">
    
    <h3>
    	<select name="type" id="type"> 
    	<option value="">Select property type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</option> 
    	<option value="ALL">All</option> 
    	<option value="factory">factory</option> 
    	<option value="house">house</option> 
    	<option value="condominium">condominium</option> 
    	</select><br>      <!---by putting the <br> here the dropdown in cascaded form instead all 3 in horizontal--->
    
    	<select name="location" id="location" >
    	<option value="">Select property location &nbsp;:</option> 
    	<option value="ALL">All</option> 
    	<option value="bangkok">bangkok</option> 
    	<option value="Patpong">Patpong</option> 
    	<option value="Chiang Mai">Chiang Mai</option> 
    	</select> <br>    <!---by putting the <br> here the dropdown in cascaded form instead all 3 in horizontal--->
    
    	<select name="price" id="price" >
    	<option value="">Select price &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</option> 
    	<option value="ALL">All</option> 
    	<option value="code1">THB0 - THB50</option> 
    	<option value="code2">THB50 - THB100</option>
    	<option value="code3">THB50 - THB100</option> 
    	</select> 
    
    	<input type="button" Value="Submit" onclick="ajaxFunction(1)">
    	</form> <br /> 
    </h3>
    
    <!----------------------------------------------Property Information to be listed here ----------------------------------------------------------->
    <h4>
    
    	<div id="ajaxDiv"><b>Please select your property search criteria in the search box on the left of this webpage</b></div>
    </h4>
    
    
     <!------------------------------------ Javascript for photo slides ------------------------------------------------>
    
    <script>
    	// Load the classic theme
    	Galleria.loadTheme('galleria.classic.min.js');
    	// Initialize Galleria
    	$('#galleria').galleria();
    </script>
    
    
    
    </body>
    </html>

      I am thinking of some sort of combination of example : $gType = 'ALL' and $gType = $_GET['type'] ? ermm ...

        been trying all weekend appreciate any feedback 🙁

          Hi akmal1981,
          I quite don`t get your idea.

          I am thinking of some sort of combination of example : $gType = 'ALL' and $gType = $_GET['type'] ?

          This deosn`t make any sense? you want to select all types of properties and type equal to some specific type? 😕

            uhmmm ... please ignore my earlier idea , i didnt know what i was writing about im still looking for some sample codes in website and tried few combinations but still stuck

              for benefits of other noobs , the solution is :

              In HTML

              <body onload="javascript:ajaxFunction(1);">
              
              <h3>
              	<select name="type" id="type"> 
              	<!---<option value="">Select property type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</option> --->
              	<option value="ALL">All</option> 
              	<option value="factory">factory</option> 
              	<option value="house">house</option> 
              	<option value="condominium">condominium</option> 
              	</select><br>      <!---by putting the <br> here the dropdown in cascaded form instead all 3 in horizontal--->
              
              	<select name="location" id="location" >
              	<!---<option value="">Select property location &nbsp;:</option> --->
              	<option value="ALL">All</option> 
              	<option value="bangkok">bangkok</option> 
              	<option value="Patpong">Patpong</option> 
              	<option value="Chiang Mai">Chiang Mai</option> 
              	</select> <br>    <!---by putting the <br> here the dropdown in cascaded form instead all 3 in horizontal--->
              
              	<select name="price" id="price" >
              	<!---<option value="">Select price &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</option> --->
              	<option value="ALL">All</option> 
              	<option value="code1">THB0 - THB50</option> 
              	<option value="code2">THB50 - THB100</option>
              	<option value="code3">THB50 - THB100</option> 
              	</select> 
              
              	<input type="button" Value="Submit" onclick="ajaxFunction(1)">
              	</form> <br /> 
              </h3>
              

              In PHP :

              //  When i use this code I will get (1) i.e. all properties result readily displayed in webpage 
              $gType = 'ALL'; 
              $gLocation = 'ALL'; 
              $gPrice = 'ALL'; 
              $gHref="ContactUs_OurTeam(2).html#"; 
              
              
              
              //GOT RID OF ALL THE IF CONDITIONS. IF THE VALUES ARE NOT EQUAL TO 'ALL', USE THEM IN THE QUERY 
              
              $subQuery = array(); 
              
              $gType = $_GET['type']; 
              $gLocation = $_GET['location']; 
              $gPrice = $_GET['price']; 
              
              if($gType <> 'ALL') 
                  $subQuery[] = 'type = \''.$gType.'\'';      
              if($gLocation <> 'ALL') $subQuery[] = 'location = \''.$gLocation.'\'';
              if($gPrice <> 'ALL') $subQuery[] = 'price = \''.$gPrice.'\'';

              Feeding 'ALL' straight away , hence I will get (1) and (2) 😃

              If there are no more comments , I will mark this thread solved by tomorrow. Many thanks to all !!!!!!

                being a noob, i always thought there'd be a fancy code solutions to this but realized this morning it took calm thoughts and simple solution ,

                  Write a Reply...