Freedom-n-Democrazy Posted September 24, 2011 Share Posted September 24, 2011 LOL note the topic is a pun at Help Vampires... I actually have an unchallenging question. I'm trying to echo out a column in a MySQL table. I'm getting one field echoing, but not the others: I'm using this code style, but I've made a small mistake somewhere at the end, I've tried many combinations trying to fix it, but haven't succeeded.. $query = "select email from newsletters"; $result = mysql_query($query); $row = mysql_fetch_array($result); foreach ($row as $email) {echo $email;} I got the argument foreach() straight out of the manual and copied the syntax style exactly as was demonstrated in the example, but its still not working. What have I done wrong? Quote Link to comment https://forums.phpfreaks.com/topic/247753-ive-got-a-good-challenge-for-you-php-grand-masters/ Share on other sites More sharing options...
Pikachu2000 Posted September 24, 2011 Share Posted September 24, 2011 The fetch function, and the the foreach() loop need to be within a while loop. The foreach loop will only iterate over the array of the one returned record. Quote Link to comment https://forums.phpfreaks.com/topic/247753-ive-got-a-good-challenge-for-you-php-grand-masters/#findComment-1272252 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 24, 2011 Author Share Posted September 24, 2011 Thanks mate, it worked. Quote Link to comment https://forums.phpfreaks.com/topic/247753-ive-got-a-good-challenge-for-you-php-grand-masters/#findComment-1272253 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 24, 2011 Author Share Posted September 24, 2011 Oops. Quote Link to comment https://forums.phpfreaks.com/topic/247753-ive-got-a-good-challenge-for-you-php-grand-masters/#findComment-1272363 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 24, 2011 Author Share Posted September 24, 2011 The fetch function, and the the foreach() loop need to be within a while loop. The foreach loop will only iterate over the array of the one returned record. This thread is be solved, but I would like to know what "iterate over the array" means in English. Can someone please explain? I ask because although I can see how the solution worked for my issue, 'iterating' may apply to future PHP functions, and I don't know when the word should be used.. so hopefully in street- talk will help me understand better. Quote Link to comment https://forums.phpfreaks.com/topic/247753-ive-got-a-good-challenge-for-you-php-grand-masters/#findComment-1272375 Share on other sites More sharing options...
the182guy Posted September 24, 2011 Share Posted September 24, 2011 iterate over the array simply means loop through it, for example $myArray = array('one', 'two', 'three'); // iterate over the array foreach($myArray as $item) { } Iterate just means loop. Quote Link to comment https://forums.phpfreaks.com/topic/247753-ive-got-a-good-challenge-for-you-php-grand-masters/#findComment-1272381 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 24, 2011 Author Share Posted September 24, 2011 Ahh, thanks dude. Is there any difference in using "iterate" and "loop"? Thanks in advance, I am going to sleep now. Quote Link to comment https://forums.phpfreaks.com/topic/247753-ive-got-a-good-challenge-for-you-php-grand-masters/#findComment-1272386 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.