php array from mysql

后端 未结 2 1800
说谎
说谎 2021-01-28 07:41

I\'m using PHP to get a value from MySQL. My table has this form:

COL1 = MAIL mail@mail.com
COL2 = NAME myname

and I\'m getting from the databa

相关标签:
2条回答
  • 2021-01-28 08:41

    Either specify MYSQLI_ASSOC after your query, or use mysqli_fetch_assoc. from the manual:

    resulttype This optional parameter is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH.

    By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to the mysqli_fetch_row() function. The final option MYSQLI_BOTH will create a single array with the attributes of both.

    Manual: http://us2.php.net/mysqli_fetch_array

    0 讨论(0)
  • From the manual

    mysqli_fetch_array() is an extended version of the mysqli_fetch_row() function. In addition to storing the data in the numeric indices of the result array, the mysqli_fetch_array() function can also store the data in associative indices, using the field names of the result set as keys.

    What you you're really looking for is mysqli_fetch_assoc()

    Returns an associative array that corresponds to the fetched row or NULL if there are no more rows.

    0 讨论(0)
提交回复
热议问题