473,382 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Some help with some code.

Chrisjc
375 256MB
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 1245
Chrisjc
375 256MB
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
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...
9
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...
10
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...
22
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
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...
53
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...
2
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. ...
193
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...
6
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...
20
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.