sayedsohail Posted March 16, 2007 Share Posted March 16, 2007 Hi all, I wish to store retreve value from my sql using session array and retrieve this value. here is my while statement, which is displaying records from my database. I want to store all this value in an array using session and than retrieve this value on click of the table row. Please help. while(list($id, $name) = mysql_fetch_array($result)) {print "<tr><td>$id></td><td>$name></td></tr>"; } Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/ Share on other sites More sharing options...
sayedsohail Posted March 16, 2007 Author Share Posted March 16, 2007 this is my blank array, but how do i pass the value into this array. please help. session_start(); // create an blank array, $my_array=array(); // put the array in a session variable $_SESSION['values']=$my_array; Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-208991 Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 <?php session_start(); // create an blank array, $my_array=array(); while(list($id, $name) = mysql_fetch_array($result)) { $my_array[] = "<tr><td>$id></td><td>$name></td></tr>"; } // put the array in a session variable $_SESSION['values']=$my_array; ?> Is that what you mean? Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-208995 Share on other sites More sharing options...
sayedsohail Posted March 16, 2007 Author Share Posted March 16, 2007 Thanks, this is exactly what i needed, plus i wish to retain the values of the tr(row)on onclick method, so i can refer this value on page refresh, any help would be greatly appreciated.<?php session_start(); // create an blank array, $my_array=array(); while(list($id, $name) = mysql_fetch_array($result)) { "<tr onclick=$my_array[] ><td>$id></td><td>$name></td></tr>"; } // put the array in a session variable $_SESSION['values']=$my_array; ?> Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209039 Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 Wow dude you just obliterated that. <?php session_start(); // create an blank array, $my_array=array(); while(list($id, $name) = mysql_fetch_array($result)) { $my_array[] = "<tr onclick='javacodehere'><td>$id></td><td>$name></td></tr>"; } // put the array in a session variable $_SESSION['values']=$my_array; ?> Also the [ code ] and [ /code ] tags are your friends, not your enemies. Remember to define a variable = to a value it goes $variable = $value; you cannot set a variable to a value by doing it how you were trying to above. Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209047 Share on other sites More sharing options...
sayedsohail Posted March 16, 2007 Author Share Posted March 16, 2007 Hi, I changed the values, but how do i refer the row click values from the session values. Here is the modified code: <?php session_start(); // create an blank array, $my_array=array(); while(list($id, $name) = mysql_fetch_array($result)) { $my_array[] = "<tr onclick='passvar($id, &name,this)'><td>$id></td><td>$name></td></tr>"; } // put the array in a session variable $_SESSION['values']=$my_array; ?> function passvar(pan,rec,obj) { var bage = pan; var cid = rec; document.location.href="sitedetail.php?page="+bage+"&cid="+cid; } Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209120 Share on other sites More sharing options...
sayedsohail Posted March 16, 2007 Author Share Posted March 16, 2007 i had also tried this method, but its not retaining the values of the row i clicked, instead its retained the value of the last row inside the table. $count = 1; while ($row= mysql_fetch_array($result)) { $name = $row["NAME"]; $ID = $row["ID"]; $_SESSION['s_name'] = $name; $_SESSION['s_ID'] = $ID; echo "$name"; echo "$ID"; $count ++; } Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209125 Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 foreach ($_SESSION['values'] as $array) { $name = $array["NAME"]; $ID = $array["ID"]; $_SESSION['s_name'] = $name; $_SESSION['s_ID'] = $ID; echo "$name"; echo "$intersection"; } Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209126 Share on other sites More sharing options...
sayedsohail Posted March 16, 2007 Author Share Posted March 16, 2007 thanks, but its making me crazy. this is my while statement count = 1; while(list($id, $name) = mysql_fetch_array($result)) { $my_array[] = "<tr onclick='passvar($id, &name,this)'><td>$id></td><td>$name></td></tr>"; } // put the array in a session variable $_SESSION['values']=$my_array; count++; ?> my javascript funciton retains all the values and i can refer all the values in my array, but how do i refer the value of the clicked row from the array. please help the next Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209131 Share on other sites More sharing options...
redarrow Posted March 16, 2007 Share Posted March 16, 2007 <?php session_start(); while(list($id, $name) = mysql_fetch_array($result)) { $_SESSION['name']=$name; $_SESSION['id']=$id; } echo"<a href='whatever.php?id=".$_SESSION['id'].">go to new page</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209140 Share on other sites More sharing options...
sayedsohail Posted March 16, 2007 Author Share Posted March 16, 2007 Redarrow, thanks it works, but only one problem, since the i got loads of records, the $_SESSION['name']=$name; retains only the the last row $name and $id. I would like to refer the click row values to next page. Any possibility of doing so.. please help. <?php session_start(); while(list($id, $name) = mysql_fetch_array($result)) { $_SESSION['name']=$name; $_SESSION['id']=$id; echo "<TR onclick="<a href='whatever.php?id=".$_SESSION['id'].">go to new page</a>>" <TD>$name</td><TD>$id</td></tr> } ?> Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209150 Share on other sites More sharing options...
sayedsohail Posted March 17, 2007 Author Share Posted March 17, 2007 i am stuck any ideas guys. please help. Link to comment https://forums.phpfreaks.com/topic/43028-store-while-statment-data-in-array-using-session-and-retrieve/#findComment-209369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.