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
https://forums.phpfreaks.com/topic/176810-solved-i-think/
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
https://forums.phpfreaks.com/topic/176810-solved-i-think/#findComment-932231
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
https://forums.phpfreaks.com/topic/176810-solved-i-think/#findComment-932233
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.