phpretard Posted October 7, 2009 Share Posted October 7, 2009 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! Quote Link to comment Share on other sites More sharing options...
Dânêl Posted October 7, 2009 Share Posted October 7, 2009 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 } ?> Quote Link to comment Share on other sites More sharing options...
phpretard Posted October 7, 2009 Author Share Posted October 7, 2009 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? Quote Link to comment Share on other sites More sharing options...
Dânêl Posted October 7, 2009 Share Posted October 7, 2009 I edited my last post. read it again Quote Link to comment Share on other sites More sharing options...
phpretard Posted October 7, 2009 Author Share Posted October 7, 2009 Thanks a bagillion!!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.