Hello all, I need to edit values in a resultSet got from a SQL query. I've tried referecing it like this: foreach ($temp as &$val) { $val["place"] = "SOMETHING"; } But I'm getting "An iterator cannot be used with foreach by reference". I also tried to clone the $temp before doing that and I get a weird error instead. Can someone help me reach my goal? Thanks.
It doesnt work... I think we have to invoke it by reference to be able to change it's values. I tried this to check: $a = array(array(1), array(2), array(3), array(4), array(5), array(6)); foreach ($a as &$poop) { $poop[0]++; } print_r($a); and it works great. print (2..3..4..5..6..7)... But doing the same thing with a ResultSet doesnt work. I thought it might be read only or something like that...
I did it because I need to change the actual values of $temp. Otherwise i'd be changing values of copies of the cells of $temp.
Well it's a ResultSet so it wont help a lot: MySQLResultSet Object ( [fetchmode:protected] => 1 [conn:protected] => MySQLConnection Object ( [database:private] => test [transactionOpcount:protected] => 0 [dblink:protected] => Resource id #65 [dsn:protected] => Array ( [compat_assoc_lower] => [compat_rtrim_string] => [database] => test [encoding] => [hostspec] => ***.***.***.*** [password] => ********* [persistent] => [phptype] => mysql [port] => [protocol] => [socket] => [username] => root ) [flags:protected] => 0 [lastQuery] => SELECT threads.THREAD_ID, threads.THREAD_ID AS THREAD_ID, threads.TEXT AS TEXT, IF (date_format(GREATEST(IFNULL(threads.LAST_REPLIED,threads.CREATED_AT),IFNULL(threads.CREATED_AT,threads.LAST_REPLIED)), '%d%m%y') = date_format(CURRENT_DATE(), '%d%m%y'),date_format(GREATEST(IFNULL(threads.LAST_REPLIED,threads.CREATED_AT),IFNULL(threads.CREATED_AT,threads.LAST_REPLIED)), '%H:%i'),IF ((DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH) > GREATEST(IFNULL(threads.LAST_REPLIED,threads.CREATED_AT),IFNULL(threads.CREATED_AT,threads.LAST_REPLIED))),date_format(GREATEST(IFNULL(threads.LAST_REPLIED,threads.CREATED_AT),IFNULL(threads.CREATED_AT,threads.LAST_REPLIED)), '%b %y'),IF ((date_format(DATE_ADD(GREATEST(IFNULL(threads.LAST_REPLIED,threads.CREATED_AT),IFNULL(threads.CREATED_AT,threads.LAST_REPLIED)), INTERVAL 1 DAY), '%d%m%y') = date_format(CURRENT_DATE(), '%d%m%y')),'yesterday',date_format(GREATEST(IFNULL(threads.LAST_REPLIED,threads.CREATED_AT),IFNULL(threads.CREATED_AT,threads.LAST_REPLIED)), '%b %D')))) AS LAST_MODIFIED, users.USERNAME AS USERNAME, countries.FLAG_FILENAME AS FLAG_FILENAME, IF (ISNULL(online_users.LAST_TIMESTAMP),'offline.jpg','online.jpg') AS STATUS_FILE, 0 AS RANK FROM (threads, users, countries) LEFT JOIN online_users ON (threads.USER_ID=online_users.USER_ID) WHERE threads.ROOM_ID='4' AND threads.FATHER_ID IS NULL AND threads.USER_ID=users.USER_ID AND users.COUNTRY_ID=countries.COUNTRY_ID ORDER BY GREATEST(IFNULL(threads.LAST_REPLIED,threads.CREATED_AT),IFNULL(threads.CREATED_AT,threads.LAST_REPLIED)) DESC LIMIT 9, 20 ) [result:protected] => Resource id #126 [cursorPos:protected] => 0 [fields:protected] => [lowerAssocCase:protected] => [rtrimString:protected] => ) Code (markup):