arturo322 Posted December 6, 2010 Share Posted December 6, 2010 i tried to serialize an array in php but im not sure if i had the right syntax $field[0] = "Student Name"; $field[1] = "fail"; $field_ser = serialize($field); $field_unser = unserialize($field_ser); i think i didnt do it right Quote Link to comment https://forums.phpfreaks.com/topic/220793-serialize-unserialize/ Share on other sites More sharing options...
laffin Posted December 6, 2010 Share Posted December 6, 2010 nope that looks right $field[0] = "Student Name"; $field[1] = "fail"; $field_ser = serialize($field); print_r($field_ser); $field_unser = unserialize($field_ser); print_r($field_unser); Quote Link to comment https://forums.phpfreaks.com/topic/220793-serialize-unserialize/#findComment-1143492 Share on other sites More sharing options...
arturo322 Posted December 6, 2010 Author Share Posted December 6, 2010 oh so my syntax is correct but how can i store the string on a variable? so that i can store it on my database? Quote Link to comment https://forums.phpfreaks.com/topic/220793-serialize-unserialize/#findComment-1143493 Share on other sites More sharing options...
trq Posted December 6, 2010 Share Posted December 6, 2010 The answer to your question is.... $field_ser = serialize($field); $field_ser now holds your serialized array as a string. Don't store serialized arrays in a database if you need to search this data though. Quote Link to comment https://forums.phpfreaks.com/topic/220793-serialize-unserialize/#findComment-1143498 Share on other sites More sharing options...
arturo322 Posted December 6, 2010 Author Share Posted December 6, 2010 this was the url http://localhost/prototype/index.php?go=2 This is my actual code but it seems my code does the action twice and not only on if (go=2) statement and, there were no strings inserted on the database <?php $who = $_SESSION['who']; //$sql = "select s.scode,pl.section from subj s,pload pl where pl.scode=s.scode && pl.pid=$who"; $sql = "select s.sname,pl.plid,pl.section from subj s,pload pl where pl.scode=s.scode && pl.pid=$who"; $myquery = mysql_query($sql); $count_rows = mysql_num_rows($myquery); for($x=0;$x<$count_rows;$x++){ $fetch_value = mysql_fetch_array($myquery); //echo "<tr>$fetch_value[scode] - $fetch_value[section]</tr>"; echo "<th><a href=?go=$fetch_value[plid]>$fetch_value[sname] - $fetch_value[section]</a></th> "; } ?> <?php extract($_GET); if (isset($go)){ $sql = "select s.scode,s.sname,pl.section from subj s,pload pl where pl.scode=s.scode && pl.pid=$who"; $myquery = mysql_query($sql); $count_rows = mysql_num_rows($myquery); for($x=0;$x<$count_rows;$x++){ $fetch_value = mysql_fetch_array($myquery); if ($go = $fetch_value[scode]){ $field[0] = "Student Name"; $field[1] = "fail"; $field_ser = serialize($field); print_r($field_ser); //$field_unser = unserialize($field_ser); //print_r($field_unser); echo $filed_ser; $sql = "update pload set classrecfield='$field_ser' where plid='$go' && pid='who'"; mysql_query($sql); } } } Quote Link to comment https://forums.phpfreaks.com/topic/220793-serialize-unserialize/#findComment-1143537 Share on other sites More sharing options...
trq Posted December 6, 2010 Share Posted December 6, 2010 == is the comparison operator not = if ($go = $fetch_value[scode]){ should be.... if ($go == $fetch_value['scode']) { Quote Link to comment https://forums.phpfreaks.com/topic/220793-serialize-unserialize/#findComment-1143551 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.