glennn.php Posted June 20, 2011 Share Posted June 20, 2011 using fwrite (i can handle that fine) i'm trying to find out how i'd get the results of this query $res = mysql_query("SELECT emails FROM email_list WHERE used != '1' LIMIT ".$limit." "); while ($row = mysql_fetch_array($res)) { echo $row['emails']."<br />"; } in such a form as i can then write it to a text file... can someone help me with this, please? much obliged, gn Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/ Share on other sites More sharing options...
gizmola Posted June 20, 2011 Share Posted June 20, 2011 Just fetch them all into an array then foreach through it and write it to the file. $emails = array(); while ($row = mysql_fetch_assoc($res)) { $emails[] = $row['emails']; } foreach ($emails as $email) { // fwrite your $email } Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/#findComment-1232463 Share on other sites More sharing options...
glennn.php Posted June 20, 2011 Author Share Posted June 20, 2011 would this work? $string = $otherstuff; foreach ($emails as $email) { $string .= $email; } fwrite($fp,$string); Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/#findComment-1232467 Share on other sites More sharing options...
gizmola Posted June 20, 2011 Share Posted June 20, 2011 Yes sure, although you'll have one giant line of emails. You probably want at least to do: $string .= "$email\n"; Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/#findComment-1232470 Share on other sites More sharing options...
glennn.php Posted June 20, 2011 Author Share Posted June 20, 2011 right, thanks. and you look awfully young to know code this well... Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/#findComment-1232471 Share on other sites More sharing options...
gizmola Posted June 20, 2011 Share Posted June 20, 2011 right, thanks. and you look awfully young to know code this well... I learned php in utero. I plan to shift 100% to Haskell coding by age 5 though. Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/#findComment-1232476 Share on other sites More sharing options...
glennn.php Posted June 20, 2011 Author Share Posted June 20, 2011 good enough, you have plenty of time, then. thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/#findComment-1232477 Share on other sites More sharing options...
gizmola Posted June 20, 2011 Share Posted June 20, 2011 No worries You can mark topics solved with the button at the bottom if you would like to help us out. Quote Link to comment https://forums.phpfreaks.com/topic/239930-getting-an-array-i-think-into-a-text-file/#findComment-1232484 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.