Jump to content

Archived

This topic is now archived and is closed to further replies.

johnnyk

$row array

Recommended Posts

[code]
$row = mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"))

print_r($row);

/*outputs:
Array
(
    [0] => text
    [a] => text
    [1] => blah blah blah
    [b] => blah blah blah
)
*/
[/code]
Why is each column placed in the array twice? Is that supposed to happen?

Share this post


Link to post
Share on other sites
Yes as the mysql_fetch_array returns an array with both associative and number indices

if you want to use numbers for the array keys use this:
mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_NUM)

But if you want letters for the array keys use this:
mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_ASSOC)

Share this post


Link to post
Share on other sites
[!--quoteo(post=385777:date=Jun 19 2006, 03:43 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 19 2006, 03:43 PM) [snapback]385777[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Yes as the mysql_fetch_array returns an array with both associative and number indices

if you want to use numbers for the array keys use this:
mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_NUM)

But if you want letters for the array keys use this:
mysql_fetch_array(mysql_query("SELECT a, b FROM `table`"), MYSQL_ASSOC)
[/quote]

Why does it return it as both? Would specifying MYSQL_NUM or MYSQL_ASSOC make it return the results faster?

Share this post


Link to post
Share on other sites
Because if you dont specify the secound parameter as the the type you want the result to be return as mysql_fetch_array will retun both number indicies and associative arrays. I wont make it return the result faster, well it will but you wont be able to notice as its very small.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.