Jump to content


Photo

$row array


  • Please log in to reply
3 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 19 June 2006 - 07:37 PM

$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
)
*/
Why is each column placed in the array twice? Is that supposed to happen?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 June 2006 - 07:43 PM

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)

#3 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 19 June 2006 - 07:55 PM

[!--quoteo(post=385777:date=Jun 19 2006, 03:43 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 19 2006, 03:43 PM) View Post[/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?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 June 2006 - 08:03 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users