Link to home
Start Free TrialLog in
Avatar of Sim1980
Sim1980

asked on

Drop box loading in PHP

Hi all.

I have the file below that the end user uses to lookup records. Currently, they select a Builder/Community and then based on what the builder/community is the LOT drop down is populated, then based on what the builder/community and LOT are it then populates the BLOCK drop down. But we are running into some instances where we want to first look up by BLOCK and then LOT. How can I change my code below to allow them to first search by BLOCK and then LOT, or LOT and then BLOCK as it currently is, it's up to them to choose how to search. Or should I just create a new page that will allow them to do BLOCK and then LOT searches and keep this page as is?

Thank you in advance!

<?php 
   header("Cache-Control: private, must-revalidate, max-age=0");
  header("Pragma: no-cache");
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // A date in the past
    // First we execute our common code to connection to the database and start the session 
    require("common.php");

if(!$_SESSION['user']){
 header("Location: index.php");
 exit();
}

      $smt1 = $db1->prepare('SELECT DISTINCT FieldSuperDataEntry.BuilderCommunityID,Builder, Community FROM BuilderCommunity INNER JOIN FieldSuperDataEntry ON BuilderCommunity.BuilderCommunityID = FieldSuperDataEntry.BuilderCommunityID   WHERE UserID = :user_id ORDER BY Builder, Community');

      $smt1->execute(array(':user_id' => $_SESSION['user']['userid']));
      $data1 = $smt1->fetchAll();



$_SESSION['action_token'] = generate_secure_token(); 
?> 

<!DOCTYPE html>
<head>
  <title>Web App</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="style.css" type="text/css" />
  <link href="iphone-icon1.png" rel="apple-touch-icon">
  <script>

function ReloadPage() {
if ((/iphone|ipod|ipad.*os 6/gi).test(navigator.appVersion)) {
window.onpageshow = function(evt) {
if (evt.persisted) {
document.body.style.display = "none";
location.reload();
}
};
}
}

function showUser(str)
{
if (str=="")
{
document.getElementById("lot").innerHTML="";
return;
} if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("lot").innerHTML=xmlhttp.responseText;
}
}

xmlhttp.open("GET","loadlot.php?q="+str,true);
xmlhttp.send();
}

function showUser1(str1,str2)
{

if (str1=="")
{
document.getElementById("block").innerHTML="";
return;
} if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("block").innerHTML=xmlhttp.responseText;
}
}

xmlhttp.open("GET","loadblock.php?q1="+str1+"&q2="+str2,true);
xmlhttp.send();
}

</script>
</head>
<body onload="ReloadPage()">
<div class="wrapper">
    <div id="logo"></div>
    <form class="form4" action="LookupResults.php" method="post">
<div class="formtitle4">Field Super Lookup</div>

    		
           
    		<div class="input3">
                 <div class="inputtext">Builder/Community:</div>           
                 	<div class="inputcontent" ><select name="BuilderCommunity" id="BuilderCommunity" onchange="showUser(this.value)" style="width: 250px"><option selected="selected"></option>    
                
                <?php foreach($data1 as $row) { printf("<option value='%s'>%s --- %s </option>", html_escape($row['BuilderCommunityID']), html_escape($row['Builder']), html_escape($row['Community'])); }?>
                 	</select></div>
               
                <br>
                <br>
                <br>
                <div class="inputtext">Lot:</div> 
                    <div class="inputcontent" ><select name="lot" id="lot" onchange="showUser1(this.value, BuilderCommunity.value)" style="width: 250px">
                            
                     </select></div>
                <br>
                <br>
                <br>                      
                <div class="inputtext">Block:</div> 
                    <div class="inputcontent" ><select name="block" id="block"  style="width: 250px"><option selected="selected"></option>    
                            
                     </select></div>
                
             </div> 
                
               

               
		 <div class="input nobottomborder">    			
		 </div>          
                		
            
        <input type="hidden" name="action_token" value="<?php echo html_escape($_SESSION['action_token']) ?>" />
 
     
			<div class="buttons" align = center>

				<input class="button1"  type="submit" value="Lookup"/>
				<input class="button1"  type="submit" formaction="Menu.php" value="Menu" /> 

		
			</div>


</form>
</body>
</html>

Open in new window


loadlot.php:

<?php
    // First we execute our common code to connection to the database and start the session 
    require("common.php");
    
    if(!$_SESSION['user']){
        header("Location: index.php"); 
        exit();
        }

$smt1 = $db1->prepare('SELECT DISTINCT Lot FROM FieldSuperDataEntry WHERE BuilderCommunityID = :q ORDER BY Lot');


$smt1->execute(array(':q' => $_GET["q"]));
$data1 = $smt1->fetchAll();


printf("<option selected></option>");
foreach ($data1 as $row){
   printf("<option>%s</option>", html_escape($row['Lot']));
}
?>

Open in new window


loadblock.php:

<?php
    // First we execute our common code to connection to the database and start the session 
    require("common.php");
    
    if(!$_SESSION['user']){
        header("Location: index.php"); 
        exit();
        }

$smt1 = $db1->prepare('SELECT Block FROM FieldSuperDataEntry WHERE BuilderCommunityID = :q2 AND Lot = :q1 ORDER BY Block');
$smt1->execute(array(
    ':q1' => $_GET["q1"],
    ':q2' => $_GET["q2"]
    )    
    );

$data1 = $smt1->fetchAll();

printf("<option selected></option>");
foreach ($data1 as $row){
  printf("<option>%s</option>", html_escape($row['Block']));
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sim1980
Sim1980

ASKER

Will do. Thanks!
Thanks for the points and thanks for using EE.  I think that will give you the best "bang for the buck." ~Ray