mkosmosports Posted February 6, 2007 Share Posted February 6, 2007 Hey, Ive got the following loop which loads a whole bunch of data from a query into an array. while ( $row = mysql_fetch_array($alltransfers, MYSQL_ASSOC) ) { $alltrarr[] = array('id' => $row["ID"], 'date' => $row["DATE_FORMAT(TP.START_DATE,'%m')"], 'pos' => $row["CODE"], 'nickname' => $row["NICK_NAME"], 'fullname' => $row["FULL_NAME"], 'toteam' => $row["QUICK_NAMEto"], 'fromteam' => $row["QUICK_NAMEfrom"], 'status' => $row["STATE"], 'sum' => $row["TRANSFER_SUM"]); } Then, I load that array into the session. $_SESSION['trdata'] = $alltrarr; Is there a way I can have the loop load the query data directly into the session array, so I dont have to essentially create two arrays, like in the above case "$alltrarr" and $_SESSION['trdata']? Thanks Link to comment https://forums.phpfreaks.com/topic/37242-session-arrays/ Share on other sites More sharing options...
genericnumber1 Posted February 6, 2007 Share Posted February 6, 2007 what's wrong with doing something like while ( $row = mysql_fetch_array($alltransfers, MYSQL_ASSOC) ) { $_SESSION['trdata'][] = array('id' => $row["ID"], 'date' => $row["DATE_FORMAT(TP.START_DATE,'%m')"], 'pos' => $row["CODE"], 'nickname' => $row["NICK_NAME"], 'fullname' => $row["FULL_NAME"], 'toteam' => $row["QUICK_NAMEto"], 'fromteam' => $row["QUICK_NAMEfrom"], 'status' => $row["STATE"], 'sum' => $row["TRANSFER_SUM"]); } or spaced for sanity (same as above just without the eye bleeding) while ( $row = mysql_fetch_array($alltransfers, MYSQL_ASSOC) ) { $_SESSION['trdata'][] = array( 'id' => $row["ID"], 'date' => $row["DATE_FORMAT(TP.START_DATE,'%m')"], 'pos' => $row["CODE"], 'nickname' => $row["NICK_NAME"], 'fullname' => $row["FULL_NAME"], 'toteam' => $row["QUICK_NAMEto"], 'fromteam' => $row["QUICK_NAMEfrom"], 'status' => $row["STATE"], 'sum' => $row["TRANSFER_SUM"] ); } Link to comment https://forums.phpfreaks.com/topic/37242-session-arrays/#findComment-177930 Share on other sites More sharing options...
mkosmosports Posted February 6, 2007 Author Share Posted February 6, 2007 Hey, Ive tried this before, however it puts everything in another array, and this produces unexpected results later on..... Link to comment https://forums.phpfreaks.com/topic/37242-session-arrays/#findComment-177953 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.