用SQL更新php数组

I am a noob, but trying my best to get this to work, i have been looking the entire night and still can not get it to work basically,

i need an array from SQL to be printed out like this.

$data = array(
 array(
'id' => "1",
'title' => "First image",
'url' => "http://www.example.org/1",
'width' => "200",
'height' => "283",
'image' => "../sample-images/image_1_big.jpg",
'preview' => "../sample-images/image_1.jpg"
),
 array(
'id' => "2",
'title' => "Second image",
'url' => "http://www.example.org/2",
'width' => "200",
'height' => "300",
'image' => "../sample-images/image_2_big.jpg",
'preview' => "../sample-images/image_2.jpg"
  ),
 array(
'id' => "3",
'title' => "Third image",
'url' => "http://www.example.org/3",
'width' => "200",
'height' => "252",
'image' => "../sample-images/image_3_big.jpg",
'preview' => "../sample-images/image_3.jpg"
 ),
  array(
'id' => "4",
'title' => "Fourth image",
'url' => "http://www.example.org/4",
'width' => "200",
'height' => "158",
'image' => "../sample-images/image_4_big.jpg",
'preview' => "../sample-images/image_4.jpg"
  ),
  array(
'id' => "5",
'title' => "Fifth image",
'url' => "http://www.example.org/5",
'width' => "200",
'height' => "300",
'image' => "../sample-images/image_5_big.jpg",
'preview' => "../sample-images/image_5.jpg"
  ),
  array(
'id' => "6",
'title' => "Sixth image",
'url' => "http://www.example.org/6",
'width' => "200",
'height' => "297",
'image' => "../sample-images/image_6_big.jpg",
'preview' => "../sample-images/image_6.jpg"
 ),
 array(
'id' => "7",
'title' => "Seventh image",
'url' => "http://www.example.org/7",
'width' => "200",
'height' => "200",
'image' => "../sample-images/image_7_big.jpg",
'preview' => "../sample-images/image_7.jpg"
),
 array(
'id' => "8",
'title' => "Eight image",
'url' => "http://www.example.org/8",
'width' => "200",
'height' => "200",
'image' => "../sample-images/image_8_big.jpg",
'preview' => "../sample-images/image_8.jpg"
  ),
  array(
'id' => "9",
'title' => "Ninth image",
'url' => "http://www.example.org/9",
'width' => "200",
'height' => "398",
'image' => "../sample-images/image_9_big.jpg",
'preview' => "../sample-images/image_9.jpg"
 ),
  array(
'id' => "10",
'title' => "Tenth image",
'url' => "http://www.example.org/10",
'width' => "200",
'height' => "267",
'image' => "../sample-images/image_10_big.jpg",
'preview' => "../sample-images/image_10.jpg"
  )
 );

At the moment i have managed to get a printout like this

 Array
  (
   [0] => Array
    (
        [0] => 1
        [id] => 1
        [1] => First image
        [title] => First image
        [2] => http://www.example.org/1
        [url] => http://www.example.org/1
        [3] => 200
        [width] => 200
        [4] => 283
        [height] => 283
        [5] => ../sample-images/image_1_big.jpg
        [image] => ../sample-images/image_1_big.jpg
        [6] => ../sample-images/image_1.jpg
        [preview] => ../sample-images/image_1.jpg
    )

[1] => Array
    (
        [0] => 2
        [id] => 2
        [1] => Second image
        [title] => Second image
        [2] => http://www.example.org/2
        [url] => http://www.example.org/2
        [3] => 200
        [width] => 200
        [4] => 300
        [height] => 300
        [5] => ../sample-images/image_2_big.jpg
        [image] => ../sample-images/image_2_big.jpg
        [6] => ../sample-images/image_2.jpg
        [preview] => ../sample-images/image_2.jpg
    )

  [2] => 
)

my code at the moment is this,

 <?php
 // Our data source
 $conn = mysql_connect("IP", "USERNAME", "PASSWORD");

 if (!$conn) {
     echo "Unable to connect to DB: " . mysql_error();
     exit;
 }

 if (!mysql_select_db("MYSQLDB")) {
     echo "Unable to select mydbname: " . mysql_error();
     exit;
 }
 //= Query ========================//
 $sql=mysql_query("select * from DB_TABLE");


 while($data[]=mysql_fetch_array($sql));

 echo "<pre>";

 print_r ($data);

 echo "</pre>";

 ?>

If you want the particular formatting that you posted then this should work (I didn't test it):

$foo = "array (
";
while ($row=mysql_fetch_assoc($sql)){
    $foo.= "array (
";
    foreach ($row as $key => $value){
        $foo .= "'{$key}' => \"{$value}\",
";
    }
    $foo = substr($foo,0,strlen($foo)-2)."
";//removes the comma at the end
    $foo .="),
";
}
$foo = substr($foo,0,strlen($foo)-2)."
";//removes the comma at the end
$foo .= ');';
echo '<pre>'.$foo.'</pre>';

You'll need to change mysql_fetch_array($sql) to mysql_fetch_array($sql, MYSQL_ASSOC) to get only the associative array.

Either

while($data[]=mysql_fetch_array($sql, MYSQL_ASSOC));

or

while($data[]=mysql_fetch_assoc($sql));

But as the MySQL extension is deprecated, you really should be using MySQLi or PDO