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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.