I have the following code:
while ($row = mysql_fetch_array($result, MYSQL_NUM)) { for ($i=0; $i<count($row); $i++) { (DO THING HERE) $row[$i] = str_replace('\n', ' ', $row[$i]); $row[$i] = str_replace('\r', ' ', $row[$i]); } }
I basically want to do, if the associative array key is equal to ’email’ (so $row[’email’]) then append ‘@gmail.com’ to it.
See the
MYSQL_NUMyou have there? That is going to return your data using the column indexes as keys (ie 0, 1, 2, etc).You must either
a) find out which column index the
emailfield is and do:b) OR you can change
MYSQL_NUMtoMYSQL_ASSOC, and do:Note the
'&'before$valueto make it a reference.I would do the latter (I prefer
foreachtofor🙂