[wd_asp elements=’search’ ratio=’100%’ id=1]

Dual dropdown populate (both from database)

30th January 2014

MySql

mysql codehaven category

2 Versions (mysqli and mysql)

CREATE TABLE makemodel (
id int(11) NOT NULL,
make varchar(40) NOT NULL,
model varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO makemodel (id, make, model) VALUES
(1, 'ford', 'fiesta'),
(2, 'bmw', '3 series'),
(3, 'ford', 'fiesta'),
(4, 'bmw', '3 series');

Mysqli version

dualdropdown.php



query($sql)){
die('There was an error running the query [' . $mysqli->error . ']');
}

?>




get_child.php

real_escape_string($pc_id);

$sql = "select distinct model from makemodel where make='".$pc_id."'";
if(!$result = $mysqli->query($sql)){
die('There was an error running the query [' . $mysqli->error . ']');
}

if(mysqli_num_rows($result))
{
while($row = mysqli_fetch_array($result))
{
echo "";
}
}
}
?>

older version mysql

dualdropdown.php






get_child.php
".ucfirst($row['model'])."";
}
}
}
?>