In SQL select query while loop you can used ID fields as array key, it's simple. Here is example for that:
<?php
$selRes=mysql_query("SELECT id, name FROM TableName order by id DESC";
if(mysql_affected_rows()>0)
{
$data=array();
while($rowSale=mysql_fetch_array($selRes))
{
$data[$row[0]] = $rowSale[1];
}
}
//Output
print_r($data);
array([1]=>'name1',[2]=>'name2',[3]=>'name3');
?>
Enjoy!
No comments:
Post a Comment