Jump to content

php expert needed for this one


jjsquared

Recommended Posts

Hello,

 

I'm trying to make a triple-combo dependent dropdown menu.  I have preexisting code that I want to use.  This code uses the xajax library.  The code works great, the only problem is, it is static information.  The code populates the drop downs based on arrays.  What I need to do is instead of static arrays, have this info be populated dynamically from my database.  I don't know php that well so will really need some hand holding.  Basically what I'm looking for is the solution to my problem, not just a suggestion.  The code is below:

 

<?
require_once('xajax.inc.php');
class myXajaxResponse extends xajaxResponse  {
  function addCreateOptions($sSelectId, $options) {
    $this->addScript("document.getElementById('".$sSelectId."').length=1");
    if (sizeof($options) >0) {
       foreach ($options as $option) {
         $this->addScript("addOption('".$sSelectId."','".$option."','".$option."');");
       }
     }
  }
}
?>
<?
$mode = array('air','water','land');
$transports = array(
  'air'=>array('plane','helicopter','air-baloon'),
  'water'=>array('boat','watersky','submarine'),
  'land'=>array('motorcycle','car')
);
$brands = array(
  'plane'=>array('Boeing707', 'F-16', 'Columbia'),
  'helicopter'=>array('BayWatch Heli', 'Police Heli'),
  'air-baloon'=>array('Zeppelin'),
  'boat'=>array('Baywatch Safeguard Boat', 'JetBoat'),
  'watersky'=>array('JetSky','Board-Sky'),
  'submarine'=>array('K-19'),
  'motorcycle'=>array("Yamaha", "Harley Davidson", "Ducati"),
  'car'=>array("Hummer", "Renault", "Porsche")
);
$xajax = new xajax();
//$xajax->debugOn();

// adds an option to the select 
function addTransports($selectId, $mode) {
  global $transports;
  $objResponse = new myXajaxResponse();
  $data = $transports[$mode];
  $objResponse->addCreateOptions($selectId, $data);
  return $objResponse->getXML();
}
function addBrands($selectId, $transport) {
  global $brands;
  $objResponse = new myXajaxResponse();
  $data = $brands[$transport];
  $objResponse->addCreateOptions($selectId, $data);
  return $objResponse->getXML();
}
$xajax->registerFunction("addTransports");
$xajax->registerFunction("addBrands");
$xajax->processRequests();
?>
<?
if (isset($_POST['Submit'])) {
  print_r($_POST);
}
?>
<html>
<head>
<title>AJAX Dynamic Drop Down Tutorial</title>
<?
$xajax->printJavascript();
?>
<script type="text/javascript">
  function addOption(selectId, val, txt) {
    var objOption = new Option(txt, val);
     document.getElementById(selectId).options.add(objOption);
   }
</script>
</head>
<body>
<form name="form1" method="POST" action="">
Type : 
<select name="type" id="type" onChange="xajax_addTransports('transports', document.form1.type.value)">
  <option value="">--select--</option>
  <? foreach ($mode as $mod) { ?>
  <option value="<?= $mod?>"><?= $mod?></option>
  <? } ?>
</select>
Transportation : 
<select name="transports" id="transports" onChange="xajax_addBrands('brands', document.form1.transports.value)"><option value="">--select--</option>
</select>
Brands : 
<select name="brands" id="brands"><option value="">--select--</option>
</select>
<input type="submit" value="Submit" name="Submit" id="Submit">
</form>
</body>
</html>

 

So basically I need the $mode, $transports and $brands arrays to be dynamic.  I'm making a countries, regions, cities drop down menu. So #mode will pull the countries and the countryid, $transports will pull the region based on the countryid from first selection, and $brands will pull the cities based on the regionid from the second selection.  Sounds easy enough but I'm struggling.

 

Any help would be greatly appreciated.

 

Thanks,

 

jjsquared

 

 

Link to comment
Share on other sites

Firstly, by titling your post as "php expert needed for this one" you are sure to alienate people. As you said yourself, you have no experience in php, so how can you possibly decide what problem might need an 'expert'.

 

Second, if you want someone to do this for you (and i assume that is the case, given the rather naff attitude - 'Basically what I'm looking for is the solution to my problem, not just a suggestion' ), then try the freelance forum.

Link to comment
Share on other sites

Hi,

 

I'm sorry if I came off with an attitude. I've been struggling with this problem for some time now and it was getting on my nerves.  What I'm looking for is any help I can get reallly to point me in the right direction.  I'm sure I don't need a php expert, that was pure speculation.  A solution would be nice obviously, but I'll take any help I can get at this point.

 

Thanks for writing back.

 

jjsquared

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.