Solved

Drop box loading in PHP

Posted on 2013-10-28
3
295 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How Close unsubmited attempts 10 46
How do I Enable submit button only if listbox has items 4 34
How do I speed up this PDO query 4 15
Make Float not to Wrap 14 26
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
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)

726 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