Re: Why doesn't this code work?
| From: | Jim Lucas | Date: | Wed, 16 Apr 2003 04:34:44 +0000 |
| Subject: | Re: Why doesn't this code work? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144059@lists.php.net to get a copy of this message | ||
You need to look into the reset function and use it on the array that you
step through in the foreach call.
foreach($myArr AS $k => $v)
{
// do thinging with $k and $v
}
reset($myArr);
Try this it should work for you.
Jim
----- Original Message -----
From: "Julie Grand" <jgrand@realdcf.com>
To: <php-general@lists.php.net>
Sent: Tuesday, April 15, 2003 5:06 PM
Subject: [PHP] Why doesn't this code work?
> I am getting two arrays from a form p_id and event_id, what I need is for
> each of the values in the p_id array to then loop through the event_id so
> the result would be:
>
> p_id[1]
> event_id[1]
> event_id[2]
> p_id[2]
> event_id[1]
> event_id[2]
> p_id[3]
> event_id[1]
> event_id[2]
>
> However the result I get is:
>
> p_id[1]
> event_id[1]
> event_id[2]
> p_id[2]
> p_id[3]
>
>
> Any help on what I am doing wrong is GREATLY appreciated.
>
> $array1 = $GLOBALS['p_id'];
> while(list($value1, $value2)= each ($array1)){
> list($performance_id,$preference)= split (",", $value2);
> echo $performance_id . " -- " . $preference . "<br>";
>
> foreach ($event as $event) {
> list($event_id, $username)= split (",", $event);
> echo $performance_id . " -- " . $preference . "<br>";
> echo $event_id . " -- " . $username . "<br>";
> $SQLstr = "SELECT id FROM performance_event WHERE perf_id =
> $performance_id AND event_id = $event_id";
> $results = mysql_query($SQLstr);
> list($perf_event_id) = mysql_fetch_row($results);
> echo $perf_event_id . "<br>";
> }
> }
>