Jump to content

$row array


johnnyk

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?
Link to comment
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)
Link to comment
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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.