kingnutter Posted August 29, 2009 Share Posted August 29, 2009 Can anybody tell me why the foreach loop below is only giving me two results when there should be more? <?php $query="SELECT genre_id FROM genrelinkcd WHERE moj_id=$id"; $result=mysql_query($query); $rows=mysql_fetch_array($result); foreach ($rows as $row) { echo "$row". ', '; } ?>" I'm always getting stuck on mysql_fetch_array, mysql_fetch_rows, etc despite having to rack my brains and Googling the answer for two days each time. Can anyone point me to a tutorial that spells it all in layman terms? Link to comment https://forums.phpfreaks.com/topic/172386-foreach-fetch-frustration/ Share on other sites More sharing options...
ignace Posted August 29, 2009 Share Posted August 29, 2009 Because it should be: while ($row = mysql_fetch_assoc($result)) mysql_fetch_*() retrieves one record from the result set in differing formats (object(), array(), assoc() (proxy to array($result, MYSQL_ASSOC), row() (proxy to array($result, MYSQL_NUM) Link to comment https://forums.phpfreaks.com/topic/172386-foreach-fetch-frustration/#findComment-908900 Share on other sites More sharing options...
Malevolence Posted August 29, 2009 Share Posted August 29, 2009 1. Is $id set? 2. Are there more than 2 rows with that id? 3. Good practise to use backticks (`) the button above the tab button around SQL Tables e.g. SELECT genre_id FROM `genrelinked` WHERE etc.... although this wont fix your problem. That's all I can help you with as I don't understand the foreach statement :\ lol. http://www.brainbell.com/tutors/php/php_mysql/Using_foreach_Loops_with_Arrays.html - this looks helpful and I'm starting to understand it already =D oh and I thought of ignace's answer but then I thought the associative bit is useless however he may be correct.... Link to comment https://forums.phpfreaks.com/topic/172386-foreach-fetch-frustration/#findComment-908901 Share on other sites More sharing options...
ignace Posted August 29, 2009 Share Posted August 29, 2009 oh and I thought of ignace's answer but then I thought the associative bit is useless however he may be correct.... LOL Link to comment https://forums.phpfreaks.com/topic/172386-foreach-fetch-frustration/#findComment-908906 Share on other sites More sharing options...
Malevolence Posted August 29, 2009 Share Posted August 29, 2009 Curse you ignace! curse you! He's right, my post is a waste of time. Lol, Do I get banned for "self-flaming"? Link to comment https://forums.phpfreaks.com/topic/172386-foreach-fetch-frustration/#findComment-908927 Share on other sites More sharing options...
ignace Posted August 29, 2009 Share Posted August 29, 2009 Curse you ignace! curse you! He's right, my post is a waste of time. Lol, Do I get banned for "self-flaming"? LOL all I said was LOL and you are already cursing? I didn't say your post is a waste of time. And it's quiet hard to get banned here, so.. Link to comment https://forums.phpfreaks.com/topic/172386-foreach-fetch-frustration/#findComment-908940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.