problem with append to populate select from results
Hi everyone... I'm really stuck with this one, can't make it work...
I got a sql_list.php which return some data from the data base...
but I'm stucked when doing the loop with for to append an <option> for each result returned...
my script looks like this
$(document).ready(function() {
$.get('sql_search.php', null, (function(data) {
for (i = 0; i < data.length; i++)
{
$("#cat").append('<option value="' + data[i] + '">' + data[i] + '</option>');
}
}));
});
apparently the get method is returning each character (130)
my sql looks like this.
$sql = "SELECT * FROM tbl_cat ORDER BY name ASC";
$result = mysql_query($sql);
while ($row = mysql_fetch_object($result))
{
echo "<li>$row->name</li>";
}
I tried to return the result as an array with mysql_fetch_array... but still the same...
that tbl_cat has 8 categories...130 characters... so instead of creating 8 options for the select... it is creating 130 options... one for each character...
can anyone give me a light of what is happening, coz I cound't figure this out...