1

I have selected two colum of the database as below

$sort_query = "SELECT s_uniqid, mar_total FROM record WHERE $x='$y'";
    $run_sort = mysql_query($sort_query);
    while($sort_marks = mysql_fetch_assoc($run_sort))
    {
        foreach($sort_marks as $key => $marks)
        {
            print_r ($marks);
            echo "<br/>";
        }
    }

I am getting the result as

1000001
252
1000002
257
1000003
232
1000004
180
1000005
205
1000006
189
1000007
219
1000008
201

I want to make a new array with the element where key as 1000001, 1000002, 1000003 , 1000004 and value is 252,257,232,180 and so on. Please suggest anything.

user2642907
  • 121
  • 1
  • 1
  • 11

1 Answers1

0
$arr = array();
while($sort_marks = mysql_fetch_assoc($run_sort))
{
    $arr[$sort_marks['s_uniqid']] = $sort_marks['mar_total'];
}

If you have read the documentation for mysql_fetch_assoc(), this should be self-explanatory. Column s_uniqid is used for the keys, and column mar_total is used for the values.

PleaseStand
  • 31,641
  • 6
  • 68
  • 95