Solved

Drop box loading in PHP

Posted on 2013-10-28
3
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

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 110

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

691 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