Slip Posted August 26, 2008 Share Posted August 26, 2008 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 More sharing options...
Cosizzle Posted August 26, 2008 Share Posted August 26, 2008 I don't think PHP randomly switched hehe, perhaps you created another array with the same name $array? Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626293 Share on other sites More sharing options...
Ken2k7 Posted August 26, 2008 Share Posted August 26, 2008 Could you possible post up some code? Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626317 Share on other sites More sharing options...
Slip Posted August 26, 2008 Author Share Posted August 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626349 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Also, just use mysql_fetch_assoc(). Saves a bit of space and makes your array smaller. Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626353 Share on other sites More sharing options...
Slip Posted August 26, 2008 Author Share Posted August 26, 2008 Also, just use mysql_fetch_assoc(). Saves a bit of space and makes your array smaller. I'll have a read up on that function, Thanks! Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626356 Share on other sites More sharing options...
Ken2k7 Posted August 26, 2008 Share Posted August 26, 2008 Also, just use mysql_fetch_assoc(). Saves a bit of space and makes your array smaller. Or mysql_fetch_array() with the optional third parameter set to MYSQL_ASSOC. Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626379 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 mysql_fetch_assoc() would be faster because it wouldn't need to parse the constant. Just saying. It's your preference though. I like the one with less typing. Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626383 Share on other sites More sharing options...
akitchin Posted August 26, 2008 Share Posted August 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/121454-arrays-doing-funny-things/#findComment-626454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.