473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some help with some code.

Chrisjc
375 Contributor
I am hoping someone can help me out here. I am trying to make one drop down box pull from a database the DB name is “dealerlocater” the column it needs to pull in this drop down is called “state” Once it loads all the states in the drop down box it then needs to be able to do the following.

Once a user selects a state it will load all information listed in the ROWS of the state column I.E.

+++++++++++++++ +
+ Select Your State + Pulls from column “state” say they pick California
+++++++++++++++ +

Anything in the database with California in that column will then begin to display the rows.


Company Name:
Address:
City:
State abbreviation:
Zip:
Phone:
Website:

The database is set up like this

State company address city stateabb zip etc...
California Test Company 123 St. Test CA 99999
California Test Company 123 St. Test CA 99999
California Test Company 123 St. Test CA 99999
=============== =============== =============== ===========
So that is what the data file looks like and once they clicked on a state it will find all that match what they picked and display what ever rows I would list.

Displaying the rows is easy I just need help with the quey and the click on the state and it will search it and load whatever columns I tell it do that match with the state.

Any help would be great!!!

Here is something I tryed and its not working.

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript">
  3.  
  4. var div7 = '<p>&nbsp;</p>';
  5.  
  6. var ajax = new sack();
  7. var selstate;
  8.  
  9.  
  10. function buildtop() {
  11.     ajax.requestFile  = 'getCarInfo.php?buildtop=1';
  12.     ajax.onCompletion = makeTop;
  13.     ajax.runAJAX();
  14. }
  15.  
  16. function getPart(sel) {
  17.     selstate = sel.options[sel.selectedIndex].value;
  18.     if(selYear.length>0){
  19.         ajax.requestFile = 'getCarInfo.php?getpart=1&state='+selstae+';   
  20.         ajax.onCompletion = createPart;     
  21.         ajax.runAJAX();         
  22.     }
  23. }
  24. </script>
  25. </head>
  26.  
  27.  
  28. <?php
  29. // =========================================================
  30. //  Populate the State selection list from the database
  31. // =========================================================
  32. echo '<form action="" method="post">';
  33. echo '<select id="state" name="state" style="margin-bottom:4px;font-family: Tahoma; font-size: 10pt; height:28px;width:184px;" onchange="getList(this)">';
  34. echo '<option value="">Select Your State</option>';
  35. // =========================================================
  36. // Connection to the Database
  37. // =========================================================
  38. include ('db functions/db_connect.php');
  39. // =========================================================
  40. // SELECT year to make drop down list
  41. // =========================================================
  42. $res = mysql_query("SELECT state FROM dealerlocater WHERE 'state' GROUP BY state ORDER BY state")
  43.    or die("Invalid query: " . mysql_query());
  44. while ($row = mysql_fetch_assoc($res)) {
  45.    $st = $row['state'];
  46.    echo "<option value='$st'>$st</option>";
  47. }
  48. echo '</select>';
  49. ?>
  50.  
  51.  
  52.  
  53. <DIV ID="divmsg7">
  54.     </DIV>
  55.  
I belive using the AJAX is a waste... I think this can all be done on one page with out passing info am I correct?

If not I will need the help with the ajax...

Thank you

Chris
Jan 9 '08 #1
1 1262
Chrisjc
375 Contributor
And here is the other page.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /*************************************************************************************
  3. 1. drop down STATE
  4. **************************************************************************************/
  5. // ===============================================================================
  6. // Load Config
  7. // ===============================================================================
  8. include ('config.php');
  9. // ===============================================================================
  10. // Connection to the Database
  11. // ===============================================================================
  12. include ('db functions/db_connect.php');
  13. // =====================================================================================================
  14. // Construct list overview after user selectes state.
  15. // =====================================================================================================
  16. if( (isset($_GET['getList']) AND isset($_GET['state'])){
  17.   if(isset($_GET['getList'])) {  
  18.      $st = $_GET['state']; 
  19.  
  20.  
  21.  
  22.      $query="SELECT dealerlocater.state, ".
  23.             " FROM dealerlocater ".
  24.             " WHERE state='$st' ".
  25.             " GROUP BY dealerlocater.state ".
  26.             " ORDER BY dealerlocater.state ";
  27.   }
  28. $res = mysql_query($query)
  29.   or die("Invalid query: " . mysql_query());
  30. // ===============================================================================
  31. // read the Categories table and build the colno array in max 4 entries
  32. // ===============================================================================
  33. $cat = mysql_query("SELECT * from dealerlocater GROUP BY state ORDER BY state")
  34.   or die("SELECT Categories failed: ".mysql_error());
  35. $catArray = array();
  36. $i=0;
  37. while ($rowcat = mysql_fetch_assoc($cat)) {
  38.   $colArray[$i] = $rowcat['colno'];
  39.   $i++;
  40. } // End WHILE
  41.  
  42. // This ends the table for the TOP part of the screen
  43. // ===============================================================================
  44. if (mysql_num_rows($res) > 0) {
  45.   // build the output array sorted by category
  46.   $outArray=array();
  47.   $k=0;
  48.   while ($row = mysql_fetch_assoc($res)) {
  49.     $st = $row['state'];    
  50.     $cp = $row['company'];
  51.     $ad = $row['address'];
  52.     $ci = $row['city'];    //if (is_null($ca)) $ca ='1';
  53.     $sb = $row['stateabb']; 
  54.     $zi = $row['zip'];     
  55.     $we = $row['web'];  
  56.  
  57.     $outArray[$ca][]=array('state'             => $st, 
  58.                            'company'         => $cp,
  59.                            'address'         => $ad,
  60.                            'city'              => $ci,    
  61.                            'stateabb'        => $sb,
  62.                            'zip'             => $zi,    
  63.                            'web'                => $we);
  64.   }
  65. }
  66. else {                          // no rows selected (mysql_num_rows == 0)
  67.   echo 'No results found for your search!';
  68. }
  69.  
Jan 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2757
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like storing products in
9
13691
by: Edilmar | last post by:
Hi, First of all, I'm new in Python... I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, Eclipse, Borland C++, Perl, etc... Then, today I think IDEs like Delphi have a excelent environment to develop apps with little time. I saw many people talking about Python like a easy lang to learn and to develop. But I have look at IDEs for Python, or ways
10
3108
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting that Numerology program I wrote years ago in VB. There are times I am totally stuck (for instance, I just had an idea to put the numerical values of the alphabet and months of the year in a dictionary located in a function. Then, I can import the...
22
2285
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
1
2610
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for topics to include in a course on object-orientation that I'm going to conduct. (I will later summarize all the replies and discussion, for the
53
5747
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
2
1333
by: John Viele | last post by:
Every time I create ASP.NET pages that do any significant data access, I find myself having to deal with the same problems: managing data object creation, the SQL connection object especially. Problem 1: If I have a pile of data adapters on a page, I typically only need a single SQL connection object, though the designer always tries to add a new one for each data adapter. So I have to manually weed out the extras and set the data...
193
9649
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
6
2347
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any solution. My code can be downloaded from here: http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some scripts for GNU/Linux system (bash to be precise). All you need to know is that there are four classes. (Of course, you may...
20
4287
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.