I have a database table which have around 106 numbers of id. I want to display the id in a selected list my code is given below: // connection open string <select> <?php $list = array(); $query1 = "SELECT id FROM brandname"; $doquery1 = mysql_query($query1,$connect); while($result = mysql_fetch_array($doquery1)) { $list[] = $result; // } foreach($list as $lists) { echo "<option>$lists</option>"; } ?> </select> // connection close string i am inserting all id in the array but when i echo it, the result comes out like: ARRAY,ARRAY. how can i print my array elements in the droplist of <select>
Hello, You got array there in $lists variable thats why you are getting ARRAY in output. See here: $result is an ARRAY and you are saving ARRAY in $list variable. Now Here you are printing each element of $list which contains all ARRAY elements so better make it like: Thank you
hi you can just do that <select name='myname'> <? $query1 = "SELECT id FROM brandname"; $doquery1 = mysql_query($query1,$connect); while($result = mysql_fetch_array($doquery1)) { echo "<option >$result['id']</option>": } ?> </select>
100% accurate, i had already done this job 5, 6 times before, this is the most simple and fast method, no need to put it in array and then grabbing back from array.
agree with this. just call it directly from the DB and throw it as a select. I'll only put it in array if i wanna manipulate the select values.