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>"; } Quote Link to comment 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; Quote Link to comment 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? Quote Link to comment 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; ?> Quote Link to comment 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. Quote Link to comment 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; } Quote Link to comment 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 ++; } Quote Link to comment 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"; } Quote Link to comment 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 Quote Link to comment 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>"; ?> Quote Link to comment 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> } ?> Quote Link to comment 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. 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.