brosjr Posted August 24, 2011 Share Posted August 24, 2011 Hello all, I had some kind of same problem before and I made very hard changes on the project for that to work, but now I'm experiecing a sort of same problem and I can't change it at all so deep. I have group of number in an array that I explode: array($numbers = explode("|", $rest)); Than I "foreach it": foreach ($numbers as $n=>$num){ $sqlname = mysql_query("select name from table where number = '{$num}'"); $name = mysql_fetch_row($sqlname); echo $num." - ".$name[0]; } The result is: 51.399.517 - Danilo Piva Junior 57.716.524 - 02.067.142 - 51.629.749 - 51.109.841 - 59.852.855 - As it can be seen, the foreach returns each number ($num) holded on the array correctly, but when it need query a value from database it only returns the first value, it does not return each name ($name[0]) as expected. Please Thankx Danilo Jr. Quote Link to comment https://forums.phpfreaks.com/topic/245609-foreach-problem/ Share on other sites More sharing options...
requinix Posted August 24, 2011 Share Posted August 24, 2011 And what if you rearrange the numbers? Like 57.716.524|02.067.142|51.629.749|51.109.841|59.852.855|51.399.517 Also, make sure you're posting your actual code and not some paraphrased version of it. Quote Link to comment https://forums.phpfreaks.com/topic/245609-foreach-problem/#findComment-1261485 Share on other sites More sharing options...
brosjr Posted August 24, 2011 Author Share Posted August 24, 2011 requinix, The numbers stored on $rest array are already arranged as you sugested, and it does not matter wich number comes first, it only returns the name associated to that first number and not the others. Thank you for the tip, next time I'll not use paraphrased version of the code Quote Link to comment https://forums.phpfreaks.com/topic/245609-foreach-problem/#findComment-1261488 Share on other sites More sharing options...
requinix Posted August 25, 2011 Share Posted August 25, 2011 Thank you for the tip, next time I'll not use paraphrased version of the code So does that mean this time you did? Then how about posting the real version? Quote Link to comment https://forums.phpfreaks.com/topic/245609-foreach-problem/#findComment-1261918 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.