Often there is a record of this type:

while($x = mysql_fetch_array($z)){} 

Please tell me what is assigned to $x ?

    2 answers 2

    $ x is assigned a string from the database sample, outputted as an array. At each iteration - the next.

    Example:

    idnameinfo
    onejohnteacher
    2billprogrammer
    3hankbomzh
    1. $x = array('1','id'=>'1','john','name'=>'john','teacher','info'=>'teacher');
    2. $x = array('2','id'=>'2','bill','name'=>'bill','programmer','info'=>'programmer');
    3. $x = array('3','id'=>'3','hank','name'=>'hank','bomzh','info'=>'bomzh');

    To avoid different array indices with the same values, you need to select some type of indexes.

     $type = MYSQL_BOTH // оба типа в одном массиве. По-умолчанию $type = MYSQL_ASSOC // ассоциативный массив. Ключи равны названию столбцов $type = MYSQL_NUM // числовой массив. Ключи равны порядковому номеру столбца, начиная с 0 mysql_fetch_array($z,$type); 

      The following obtained result (row) from mysql is assigned

       $resource = mysql_query('SELECT `id`, `name` FROM `table` WHERE id>0;'); while ($x = mysql_fetch_array($resource)) { echo 'ID = '.$x['id'].'<br />'; echo 'NAME = '.$x['name'].'<br />'; echo '<br />'; } 
      • The trick is that there is a double array by default. - knes
      • Well, uh, yes, I know) In my opinion, NUM is rarely used, very much, in my experience only in ShopScript Free saw and was ready to kill)) I use object in 99% of cases. - Sh4dow pm