Jump to content

foreach problem


brosjr

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/245609-foreach-problem/
Share on other sites

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  ;)

Link to comment
https://forums.phpfreaks.com/topic/245609-foreach-problem/#findComment-1261488
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.