Welcome Guest, Not a member yet? Register   Sign In
CI & jQuery Linked dropdowns
#3

[eluser]edwin87[/eluser]
Okay i forgot a parameter what is really stupid.

Code:
$('#building').linkedSelect('<?php echo base_url();?>index.php/buildings/selectbox/building','#levels',{firstOption: 'Select a level'});

It has to be something like this:

Quote:classname/function/parameter1/parameter2

Parameter1 : Building
Paramater2 : Id to search.

But how can i fill parameter 2?


The example script with php was:

Code:
<?php

$json = array();

// Lets get the variables we passed
$search = isset($_GET['search']) ? (string) $_GET['search'] : '';

$str = isset($_GET['str']) ? (string) $_GET['str'] : '';

// Cleans query string before we run the selects below.
// Allows A-Z, a-z, 0-9, whitespace, minus/hyphen, equals, ampersand, underscore, and period/full stop.
$str = preg_replace("/[^A-Za-z0-9\s\-\=\&\_\.]/","", $str);

$str = mysql_real_escape_string($str);


switch ($search) {

   case "building":

      $sql = mysql_query("SELECT * FROM Levels WHERE BuildingPart_ID = '{$str}'");

      while ($rows = mysql_fetch_array($sql)) {

         $json[] = "{optionValue: ".$rows["Level_ID"].", optionDisplay: '".$rows["Name"]."'}";
      }

      echo '[' . implode(',', $json) . ']';

   break;

   case "levels":

      $sql = mysql_query("SELECT * FROM Rooms WHERE Level_ID = '{$str}'");

      while ($rows = mysql_fetch_array($sql)) {

         $json[] = '{"optionValue": "'.$rows["Room_ID"].'", "optionDisplay": "'.$rows["Name"].'"}';
      }

      echo '[' . implode(',', $json) . ']';

   break;

   case "rooms":

      $sql = mysql_query("SELECT * FROM Segmenten WHERE Room_ID = '{$str}'");

      while ($rows = mysql_fetch_array($sql)) {

         $json[] = '{"optionValue": "'.$rows["Segment_ID"].'", "optionDisplay": "'.$rows["Name"].'"}';
      }

      echo '[' . implode(',', $json) . ']';

   break;

   default:


      echo "Something has gone wrong!";


   break;

}
?>

You can see it want to use 2 get vars.
The first one i can fill.
But the second one does not work.


Messages In This Thread
CI & jQuery Linked dropdowns - by El Forum - 11-04-2008, 02:17 AM
CI & jQuery Linked dropdowns - by El Forum - 11-04-2008, 04:48 AM
CI & jQuery Linked dropdowns - by El Forum - 11-04-2008, 05:03 AM
CI & jQuery Linked dropdowns - by El Forum - 11-05-2008, 09:59 AM
CI & jQuery Linked dropdowns - by El Forum - 01-06-2009, 10:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB