I have this code:
<script>
var values = <?php
$sql="SELECT * FROM billing_sagenominalcodes order by code ASC";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$nominalcodes = array();
while($result=mysql_fetch_assoc($rs))
{
$nominalcodes[] = $result['code'];
}
echo json_encode($nominalcodes);
?>;
</script>
<select name="sagenominalcode" id="sagenominalcode">
<script>addOptions(document.getElementById('sagenominalcode'), values);</script>
</select>
it works exactly how i need it to but i am wondering if it is possible to display the column name "name" from the database in the select options as well as the code?
for example rather than just
123
to have it like this
123 - name
mysql_*
type functions, as they have been deprecated as of version 5.5 – Julian H. Lam Mar 21 at 0:17addOptions
does but it seems like if you augment this line$nominalcodes[] = $result['code'] . ' - ' . $result['name'];
you will be closer to your desired result. – Mark Fox Mar 21 at 0:25addOptions
could do a.split()
on the string ` - ` to retrieve both values. – Julian H. Lam Mar 21 at 0:29