Often there is a record of this type:
while($x = mysql_fetch_array($z)){} Please tell me what is assigned to $x ?
$ x is assigned a string from the database sample, outputted as an array. At each iteration - the next.
Example:
| id | name | info |
|---|---|---|
| one | john | teacher |
| 2 | bill | programmer |
| 3 | hank | bomzh |
$x = array('1','id'=>'1','john','name'=>'john','teacher','info'=>'teacher');$x = array('2','id'=>'2','bill','name'=>'bill','programmer','info'=>'programmer');$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 />'; } Source: https://ru.stackoverflow.com/questions/40175/
All Articles