So, i got a pretty bad database that i CAN’T transform.
The string is 5numbers like: 180,2345,123,5643,23534
I need to put those numbers(need to explode somehow) in a select option like this:
<select name="hotel" id="hotel" class="fieldbackend">
<option value="403">403</option>
<option value="880">880</option>
<option value="983">983</option>
<option value="648">648</option>
</select>
Presently i got this result:
<select name="hotel" id="hotel" class="fieldbackend">
<option value="undefined">undefined</option>
<option value="undefined">undefined</option>
<option value="undefined">undefined</option>
<option value="undefined">undefined</option>
<option value="403,880,983,648">403,880,983,648</option>
</select>
There is my source code:
<select class="fieldbackend" id="destination" name="destination">
<option value="">-- Destination --</option>
</select>
<select class="fieldbackend" id="hotel" name="hotel">
<option value="">-- Hôtel --</option>
</select>
There is my JS:
$(function(){
$('#destination').change(function(){
$.getJSON('/dev/select2.php', {'destination': $(this).val()}, function(data) {
var items = '';
$.each(data, function(key, val) {
items += '<option value="' + val['deHotels'] + '">' + val['deHotels'] + '</option>';
});
$('#hotel').html(items);
});
});
})
Finaly there is my php code:
$requete = "SELECT DISTINCT deHotels FROM sirev_Dests WHERE deDestName = '". $_GET['destination'] ."' ORDER BY deDestName";
$connect = mysql_connect("&&&&&&&&&&&&&&&","&&&&&&&&&&&&&&&","&&&&&&&&&&&&&&&");
mysql_select_db("&&&&&&&&&&&&&&&", $connect);
$res = mysql_query($requete) or die(mysql_error());
while ($row = mysql_fetch_assoc($res, true)) {
$items = explode(',',$row['deHotels']);
array_push($items, $row);
}
die(json_encode($items));
There is a screen of the result:
http://nsa29.casimages.com/img/2012/06/01/120601072406136633.jpg
Sorry for my english, im from quebec city.
Any one can help me to figure it out?
Try this: