Solved

Drop box loading in PHP

Posted on 2013-10-28
3
291 Views
Last Modified: 2013-10-28
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

0
Comment
Question by:Sim1980
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39606388
My guess is a new page will be the path of least resistance.  Have a link near the search boxes to cross-link the pages.

Builder/Community Search page would have a link "Search by Block / Lot"

Block/Lot Search page would have a link "Search by Builder / Community"
0
 

Author Closing Comment

by:Sim1980
ID: 39606437
Will do. Thanks!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39606600
Thanks for the points and thanks for using EE.  I think that will give you the best "bang for the buck." ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now