Solved

Drop box loading in PHP

Posted on 2013-10-28
3
289 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
Comment Utility
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
Comment Utility
Will do. Thanks!
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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)

772 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

10 Experts available now in Live!

Get 1:1 Help Now