473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to serialize() and unserialize()?

26
Hi,

Kindly help, where i did the mistake?

serialize() code:
Expand|Select|Wrap|Line Numbers
  1.     require_once('../../includes/common.php');
  2.  
  3.         $m = array();
  4.     $result = mysql_query("SELECT * from sgc where year = '2008'") or die(mysql_error());
  5.  
  6.     while($row = mysql_fetch_array($result))
  7.         {
  8.           //echo $row['nric'];
  9.           $res =mysql_query("select COURSE_TITLE_LONG, CRSE_GRADE_OFF, UNT_EARNED, nric from ite where nric = '".$row['nric']."' AND STRM = '2008'")or die(mysql_error()); 
  10.           $norows=mysql_num_rows($res);
  11.           echo $norows."<br>";
  12.  
  13.           while($rows = mysql_fetch_array($res))
  14.           {
  15.               for($i=0;$i<$norows;$i++){
  16.               $data = array("'".$rows['COURSE_TITLE_LONG']."','".$rows['CRSE_GRADE_OFF']."','".$rows['UNT_EARNED']."'");
  17.               $serial = serialize($data);
  18.               }
  19.              print $serial;
  20.  
  21.           }
  22.         }
  23.  
  24.  
  25.  
output for serialize:
Expand|Select|Wrap|Line Numbers
  1. a:1:{i:0;s:30:"'Communication Skills','U','2'";}a:1:{i:0;s:32:"'Information Technology','U','1'";}a:1:{i:0;s:31:"'Piping & Valve System','F','6'";}a:1:{i:0;s:32:"'Mechanical Fabrication','F','6'";}a:1:{i:0;s:32:"'Personal Effectiveness','U','3'";}a:1:{i:0;s:29:"'Sports & Wellness I','U','1'";}a:1:{i:0;s:24:"'Basic Numeracy','U','2'";}a:1:{i:0;s:29:"'Machinery Servicing','F','5'";}a:1:{i:0;s:33:"'Hydraulics & Pneumatics','F','7'";}
  2.  
unserialize() code:
Expand|Select|Wrap|Line Numbers
  1.     require_once('../../includes/common.php');
  2.     $data = array();
  3.     $r=1;
  4.         $result = mysql_query("SELECT meta_ite from sgc where nric = 'S9405127D'") or die(mysql_error());
  5.         $count = mysql_numrows($result);
  6.  
  7.     while($row = mysql_fetch_array($result))
  8.        {
  9.           $data = str_replace('""','"',$row['meta_ite']);
  10.         //  print $data;
  11.          $unser = unserialize($data);
  12.           print_r ($unser);
  13.  
  14. }
  15.  
Mar 10 '11 #1
4 2300
code green
1,726 Expert 1GB
Please define the problem and re-phrase the question
Mar 10 '11 #2
apssiva
26
Hi,

I am tiring to unserialize() the data, but i got below output only one line
Expand|Select|Wrap|Line Numbers
  1. "Communication Skills","S","2"
  2.  
in this unserialize() --- still have some data, its not display. pls check my previous post "serialize()" output.

kindly help me. below my code

Expand|Select|Wrap|Line Numbers
  1.     require_once('../../includes/common.php');
  2.     $data = array();
  3.     $r=1;
  4.         $result = mysql_query("SELECT meta_ite from sgc where nric = 'S9405127D'") or die(mysql_error());
  5.         $count = mysql_numrows($result);
  6.  
  7.     while($row = mysql_fetch_array($result))
  8.        {
  9.           $data = $row['meta_ite'];
  10.         //  print $data;
  11.          $unser = unserialize($data);
  12.           print_r ($unser);
  13.  
  14.  
  15.       }
  16.  
Mar 10 '11 #3
code green
1,726 Expert 1GB
It is difficult to say where the problem is because you have no testing or error trapping.
A few if statements and echos will help pinpoint the problem
Mar 10 '11 #4
apssiva
26
sorry i don't know. can you give some idea? pls....
Mar 10 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Sleeman | last post by:
Hi all, i just spent an hour rifling through code to find the cause of a problem only to find it's an oddity with serialization and recursive objects, so figured I'd post for the next person who...
1
by: Sebastian Aguilera | last post by:
Hi everyone. I have some troubles using the unserialize() function. I have serialized an array and that works perfect: echo '<input type="hidden" name="vardekedja" value="'.serialize($_POST...
2
by: Andrew | last post by:
Some have suggested that using serialize() and unserialize is faster than reading/writing an array to disk as a simple text file using $array = file('numbers.txt'); Can anyone justify this? ...
7
by: richbl | last post by:
Hello all, I have a question about unserializing a single array element from a serialized array. Can this be done, or must I first unserialize the array, and then access the element? For...
6
by: sandy | last post by:
With java servlets I can declare complex object-oriented class structures as session variables in a servlet. That means I can have a complex HTML form that submits iteratively back to the server...
2
by: onefastmustang | last post by:
I have a cookie that I serialize and set as follows.. $searchdata = $state; $searchdata = $country; $searchdata = $radius; $searchdata = $radius_zip; if ($_GET){ foreach ($_GET as $value){...
5
by: Mike | last post by:
I finally got serialize to work but now I cannot get unserialize to work. Here is my code. $settings = serialize($settings_array); echo "<INPUT TYPE='Hidden' NAME='settings'...
7
by: powellgg | last post by:
I've just taken over a PHP website and am converting it to ASP.NET (don't shoot!). I'm not a PHP guy so I'm doing a lot of searching for things that I aren't obvious, and I'm hoping I'll be able...
1
by: VooDoo | last post by:
Hi, I am using the serialize and unserialize to put and get data from mysql database. I think i could optimise the way i handle the data, but not really sure how. What is the best way to happend...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.