0

Im a bit stuck, I am able to read each row into an array but it is an associative array but I don't want that, i want a normal array ( array = ['2', '3', '4'] )

also, my table only has 1 column, so it should be easier

here is my code.

var_dump gives me :

 array(3) { [0]=> array(1) { [0]=> string(44)      
 "0Av5k2xcMXwlmdEV6NXRZZnJXS2s4T3pSNzViREN6dHc" } [1]=> array(1) { [0]=> string(44) 
 "0Av5k2xcMXwlmdDhTV2NxbXpqTmFyTUNxS0VkalZTSnc" } [2]=> array(1) { [0]=> string(44)   
 "0Av5k2xcMXwlmdDdhdVpMenBTZTltY2VwSXE0NnNmWWc" } } 

which tells me it is an assosiative array?

 $fileList = getLiveList();
    var_dump($fileList);

function getLiveList(){
    $query = "SELECT id FROM livelist";
    $result = mysql_query($query); // This line executes the MySQL query that you typed above

    $array = []; // make a new array to hold all your data

    $index = 0;
    while($row = mysql_fetch_row($result)) // loop to give you the data in an associative array so you can use it however.
    {
         $array[$index] = $row;
         $index++;
    }
    return $array;
}
Maz I
  • 3,664
  • 2
  • 23
  • 38
Joe
  • 267
  • 1
  • 6
  • 17

3 Answers3

1

Just take id (first element) from row,

$array = []; // make a new array to hold all your data
while($row = mysql_fetch_row($result)) // loop to give you the data in an associative array so you can use it however.
{
     $array[] = $row[0];
}
return $array;

Note: Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rikesh
  • 26,156
  • 14
  • 79
  • 87
1
$fileList = getLiveList();
var_dump($fileList);

function getLiveList(){
    $query = "SELECT id FROM livelist";
    $result = mysql_query($query); // This line executes the MySQL query that you typed above

    $array = []; // make a new array to hold all your data

   while($row = mysql_fetch_row($result)) // loop to give you the data in an associative array so you can use it however.
   {
       $array[] = $row[0];
   }
   return $array;
 }
syl.fabre
  • 696
  • 1
  • 7
  • 20
0

mysql_query return both indexed and associate arrays

use mysql_fetch_array or mysql_fetch_assoc based on your needs.

oh, and you should use mysqli functions instead :-)