Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looking for code/resource for vehicle lookup

Status
Not open for further replies.

progman1010

Programmer
Jan 2, 2008
108
0
0
US
i've been searching around and i can't find it- i need some code to select american vehicles:
1- Select a year; 2- select Make; 3- Select Model/Body; See this page for an example:
The key is that the boxes automatically update with the correct information. I could make the boxes if i need, but the really important part is the database.

Any help is appreciated.
 
Are you looking for code or for a database?

Code you can get help with and I would say look at AJAX, CSS and some JS. There is a PHP Class named XAJAX which, if you use it right, will make this task a breeze.

Here is a search from sourceforge.net which should help you get started
Code:
[URL unfurl="true"]http://sourceforge.net/search/?type_of_search=soft&type_of_search=soft&words=XAJAX+PHP[/URL]

I put this together for you
Code:
<?
include ('vehprocs.php');

require("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->registerFunction("vehMake");
$xajax->registerFunction("vehModel");
$xajax->processRequest();

?>
<html>
<head>
<title>Dynamic Select Boxes Using XAJAX</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<? $xajax->printJavascript('xajax'); ?>

</head>

<body>
<form name="vehicles" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Please Choose Vehicle Year</td>
    <td>
		<select name="vyear" id="vyearID" onChange="xajax_vehMake(this.value); document.getElementById('vehMake').style.display='block';">
			<option value="2000">2000</option>
			<option value="2001">2001</option>
			<option value="2002">2002</option>
			<option value="2003">2003</option>
			<option value="2004">2004</option>
			<option value="2005">2005</option>
			<option value="2006">2006</option>
			<option value="2007">2007</option>
			<option value="2008">2008</option>
		</select>
	</td>
  </tr>
<span id="vehMake" style="display:none;">
  <tr>
    <td>Please Choose Make</td>
    <td><span id="selVehMake">&nbsp;</span></td>
  </tr>
</span>
<span id="vehModel" style="display:none;">
  <tr>
    <td>Please Choose Model</td>
    <td><span id="selVehModel">&nbsp;</span></td>
  </tr>
</span>
</table>
</form>
</body>
</html>

and the PHP script that goes with it
Code:
<?

function vehMake($key) {
	$sql = 'SELECT * FROM vehicles WHERE vehYear = {$key}';
//	$dbserver = mysql_connect("localhost","user","password");
//	$query = mysql_query($sql) or die (mysql_error());
	$string = '<select name="vehMake" id="vehMakeID" onChange="xajax_vehModel(this.value); document.vehicles.vehModel.style.display=\'block\';">';
	$string .= '<option value="none">Please choose vehicle make</option>';

	$string .= '<option value="Chevy">Chevy</option>';		// remove this line
	$string .= '<option value="Ford">Ford</option>';		// remove this line
	$string .= '<option value="Nissan">Nissan</option>';	// remove this line

//	while ($row = mysql_fetch_assoc($query)) {
//		$string .= '<option value="' . $row['vehMake'] . '">' . $row['vehMake'] . '</option>';
//	}

	$string .= '</select>';
	$objResponse = new xajaxResponse();
	$objResponse->assign("selVehMake","innerHTML",$string);

	return $objResponse;

}
function vehModel($key) {
	$sql = 'SELECT * FROM vehicles WHERE vehMake = {$key}';
//	$dbserver = mysql_connect("localhost","user","password");
//	$query = mysql_query($sql) or die (mysql_error());
	$string = '<select name="vehModel" id="vehModelID">';
	$string .= '<option value="none">Please choose vehicle model</option>';

	$string .= '<option value="Sedan">Sedan</option>';		// remove this line
	$string .= '<option value="Sport">Sport</option>';		// remove this line
	$string .= '<option value="Convertible">Convertible</option>';	// remove this line

//	while ($row = mysql_fetch_assoc($query)) {
//		$string .= '<option value="' . $row['vehModel'] . '">' . $row['vehModel'] . '</option>';
//	}
	$string .= '</select>';
	$objResponse = new xajaxResponse();
	$objResponse->assign("selVehModel","innerHTML",$string);

	return $objResponse;

}
?>

Notice that for the sake of testing the scripts, I hard-coded the Make, Models. I marked these lines to be removed (// Remove this line).

I gave this code a quick test using FF and it worked OK. You can edit the code and populate the string variable accordingly from you tables.

Good luck!
 
Southbeach
OK so I know absolutely NOTHING about Ajax or mySQL (quite frankly - they are frightening as I am so unknowledgeable) however -- I have to learn this stuff (please, no comments on that ;-) so i managed to download the Ajax libraries copy the above and Yay it worked!

Now I can - looking at the script assume that this [ $dbserver = mysql_connect("localhost","user","password"); ] means the database name and login/pwd - right?

here is where I'm stumped - I have to get PHP MYSQL install it to create a database with 2 tables called respectively - vehMake - vehModel - correct?

yikes in the phpmysql does it show how to input the info to be displayed?

I know this is a lot - but if it wasn't for this thread - I would still be pardon the pun (beached) - for the record this is a great start!

 
Gees, I never got any email about your having replied on this. Where are you with this project? Still need help?

I would love to know ... Hope all is well!
 
I stalled.... I never got a reply so I did a bit of chicanery - but - I still need to follow through on this
 
Lets pick it up from here ...
Now I can - looking at the script assume that this [ $dbserver = mysql_connect("localhost","user","password"); ] means the database name and login/pwd - right?
That is correct, you must create a database and the respective tables. mysql_connect() (you can learn more here is used to open the connection to your DB. localhost is the server where the DB resides, "user" is the user ID with permissions to read, write, edit, etc DB content and "password" is the password given to said "user" ID.

here is where I'm stumped - I have to get PHP MYSQL install it to create a database with 2 tables called respectively - vehMake - vehModel - correct?
Yes, you MUST have these tables within your MySQL DB. These tables must have the information you expect to display within your select boxes.

yikes in the phpmysql does it show how to input the info to be displayed?
Not sure what you mean by this ...
 
Well I downloaded the Ajax libraries - I can create a database - how do I get the appropriate tables/info into the db?

I hav'nt downloaded phpmysql as i don't know the first thing about it?

and... I'm having to get my head back into this again - slow brain cells
 
What OS are you using?
What have you installed so far?

If LINUX, there is a LAMP which will automatically install all Apache, MySQL and PHP. That said, must LINUX flavors will install them automatically.

If Windows, there is a WAMP which will do the same thing.

These are the easiest way to get the environments set ...

I am no expert but I am working on a sequence of short articles to teach a few friends what I've learned thus far. If you wish, you can join us by reading through these articles and post your comments, questions and suggestions.
Code:
[URL unfurl="true"]http://www.fpgroups.com/index.php?Target=articles[/URL]

Regards,
 
hey southbeach- as a follow-up to this, the app actually got dropped, but I'm sorry i never wrote back. looks like the thread is coming in handy to Wulfgen anyway!

Peace.
 
Should the database `vehicles` look like this?

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| vehYear | varchar(255) | YES | | NULL | |
| vehMake | varchar(255) | YES | | NULL | |
| vehModel | varchar(255) | YES | | NULL | |
| vehType | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
 
@bigcat48,

Not sure what the nature of your question is? Oh, I guess you meant "table" not "database" ...


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Ok so I'm still "fiddlin" I have a client that has a lot of productss in lottsa stores all over the US -I'm tryng to get a drop menu of the states, then in that state whatever store carries the product would show --- (if its a chain store - like Big5 - then a list of all the stores for the selected store chain would show)

Its a dealer lookup type thing
 
gibcat48,

Are you trying to use the posted code? If so, the table content and design should transparent to the code itself. Of course, you will need to simply reference the proper columns according to how/where you use the code.

If you have specific question on the code itself or would like to share your intend of use, we might be able to provide assistance to help you through your existing problem(s).


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top