| | |
Intergrating javascript with php / mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2009
Posts: 12
Reputation:
Solved Threads: 0
hello,
i have a mysql database which i use a php script to search and display results with fields make, model, price, year and would like to add extra functionality with presumably javascript to add a drop down form field as when a particular make is selected from the list then it auto displays the relevant models only for that make.
help appreciated !
pabzzmike
i have a mysql database which i use a php script to search and display results with fields make, model, price, year and would like to add extra functionality with presumably javascript to add a drop down form field as when a particular make is selected from the list then it auto displays the relevant models only for that make.
help appreciated !
pabzzmike
Last edited by pabzzmike; Aug 18th, 2009 at 3:45 pm.
•
•
Join Date: Aug 2007
Posts: 55
Reputation:
Solved Threads: 9
•
•
•
•
hello,
i have a mysql database which i use a php script to search and display results with fields make, model, price, year and would like to add extra functionality with presumably javascript to add a drop down form field as when a particular make is selected from the list then it auto displays the relevant models only for that make.
help appreciated !
pabzzmike
<?php
//from your 2 resultsets containing the models & makes
//create a models array for each make
$models = array();
while($makerow = mysql_fetch_assoc($makeresultset)){
$j = 0;
while($row = mysql_fetch_assoc($modelresultset)){
if($row['make_name'] == $makerow['make_name'])
$models[$j++] = "'".$row['model_name']."'";
}
}
//joiining the array items to form a string separated by commas
//overally we create an array of such strings
$newModels = array();
for($i=0; $i<count($models); $++){
$newModels[$i] = implode(", ", $models[$i]);
}
//initialising the javascript array
$modelString = "" ;
for($i=0; $i<count($newModels); $++){
$modelString .= "modelArray[$i] = $newModels[$i]; " ;
}
echo "
<script language=javascript>
function fillArea(){
var modelArray = new Array();
$modelString
var value = document.getElementById('make').value;
var dest = document.getElementById('output');
switch(value){
case '1': dest.innerHTML = 'make 1 stuff' ; break;//output the modelArry[1] items here
case 2':dest.innerHTML ='make 2 stuff'; break;//output the modelArry[2] items here
case 'n': dest.innerHTML ='make 3 stuff'; break;//output the modelArry[n] items here
}
</script>
"
?>
<form>
<select id=make onchange=fillArea()>
<option value='1'>Make 1</option>
<option value='2'>Make 2</option>
<option value='n'>Make 3</option>
</select>
<form>
<div id=output>
</div>
[code]
Not revised - though that's the idea i usually use !!
![]() |
Similar Threads
- REWARD! Help me find a PHP/mySQL DEVELOPER needed (Web Development Job Offers)
- Looking for PHP / MySQL Developer (Web Development Job Offers)
- Looking for a PHP/MYSQL Programmer (Web Development Job Offers)
- Need Highly Experienced PHP/MySQL Programmer $15-$25/hour (Web Development Job Offers)
- PHP/MySQL Programmer Position (Web Development Job Offers)
Other Threads in the PHP Forum
- Previous Thread: PHP variable in link
- Next Thread: how to enter data in database from HTML form
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken cakephp checkbox class cms code cron curl database date date/time display dynamic echo email error file files folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail memmory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex registrationform remote script search seo server sessions sms soap source space sql static syntax system table tutorial update upload url validator variable video web webdesign wordpress xml youtube





