Jump to content

Array's doing funny things


Slip

Recommended Posts

Hi all,

 

This is my first post (one of many!).

 

I am having a weird problem with calling arrays when using mysql_fetch_array(). Say my array holder is $array and I want to call the column "id" from my row, I have to use $array[0] rather than $array['id'] which I have been using for sometime! It's only recently started happening. Any clues as to why PHP has switched to this method of calling arrays?

Link to comment
https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/
Share on other sites

Well here is some sample code...

 


$sql = "SELECT * FROM `tablename` WHERE `uid`={$uid}";
$res = mysql_query($sql, $link);

while($row= mysql_fetch_array($res)) {
    // Do something with $row['column_name']
}

 

Just checked the duplicate array variable and yes, I am using it ($row) in more than one place on the page! Silly me, thanks for pointing that out.

 

from the php manual:

 

Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC for the optional second parameter. It only returns an associative array.

 

performance won't matter, it just depends if you ever want to switch up which indexing you want to use.

Archived

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

×
×
  • 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.