Jump to content

[SOLVED] ++ I think


phpretard

Recommended Posts

The idea behind this code is to set multiple arrays as sessions.

 

Each array should contain 3 variables about the athlete.

 

I can only get one row to come back and I think it should have a ++ somewhere, I just don't know where???

 


while($athlete=mysql_fetch_assoc($athletearray))
{
$id[]=$athlete['id'];
$level=$athlete['level'];
$gender=$athlete['gender'];

	foreach($id as $var){

	$_SESSION['athletes'] = array($id, $gender , $level);

	} // end for each

            }free($athletearray);

//THIS IS WHAT I GET BUT I KNOW THERE SHOULD BE 2 SEPERATE ARRAYS

Array
(
    [user] => 1138227
    [athletes] => Array
        (
            [0] => 5 //<-- row id
            [1] => 1
            [2] => 3
        )

        )


)


//I NEED SOMETHING LIKE THIS

Array
(
    [user] => 1138227
    [athletes] => Array
        (
            [0] => 5 // <-- row id
            [1] => 1
            [2] => 3
        )
        (
            [0] => 4 // <-- row id
            [1] => 2
            [2] => 5
        )

)


 

Thank you!

Link to comment
Share on other sites

foreach($id as $var){

     $_SESSION['athletes'] = array($id, $gender , $level);

} 

Hi, every time this piece of code is executed array($id,$gender,$level) willi replace the previous memorized. You shoul use something like this to make it work:

 

<?php
	foreach($id as $var){

	$_SESSION['athletes'][] = array($id, $gender , $level);

	} 
?>

 

But reading better your code I think there are some other mistakes. Everytime the while is executed it adds in id array the current athlete id, then your foreach reporcesses previous ids and the new one. id shoulden't be an array and so the foreach is useless

 

while($athlete=mysql_fetch_assoc($athletearray))
<?php  
   $id=$athlete['id'];
   $level=$athlete['level'];
   $gender=$athlete['gender'];
               
      $_SESSION['athletes'][] = array($id, $gender , $level);
               
      } // end for each
            
}
?>

Link to comment
Share on other sites

That worked!!

 

But now I get a duplicate for the first one.

 

Array
(
    [user] => 1138227
    [athletes] => Array
        (
            [0] => Array
                (
                    [0] => 4 // <-- row id
                    [1] => 2
                    [2] => 5
                )

            [1] => Array
                (
                    [0] => 4 // <-- row id
                    [1] => 1
                    [2] => 3
                )

            [2] => Array
                (
                    [0] => 5 // <-- row id
                    [1] => 1
                    [2] => 3
                )

        )

)

 

any thoughts?

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.