Solved

using serialize and unseriaze to use array in mysql but unserialze only outputs last digit

Posted on 2011-03-11
2
320 Views
Last Modified: 2012-06-27
I am learning this script on how to serialize and unserilize information that is on mysql server.: the information is from multiple checkboxes ...and the information is arrayed into my dehu_id field. Then I want to print it out correctly but the script is only giving me last digit.
<?php

mysql_connect("localhost", "xxxxx", "xxxxxx") or die(mysql_error());
mysql_select_db("xxxxxxxx") or die(mysql_error());



$query="SELECT dehu_id FROM dehu_status";
$doQuery=mysql_query($query);
$numrows=mysql_num_rows($doQuery);
if($numrows>0)
{
 while($locations=mysql_fetch_array($doQuery))
  {
  $locations=unserialize($locations['dehu_id']);
	
  foreach($locations as $items)
   {
	  print $items.',';
   }
  }
}
else
{
 print 'No colors in database.';
}


$result->free;
$db->close();
?>

Open in new window

Table structure for table `dehu_status`
--

CREATE TABLE IF NOT EXISTS `dehu_status` (
  `dehu_id` varchar(20) NOT NULL,
  `todays_date` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `work_order_uid` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `dehu_status`
--

INSERT INTO `dehu_status` (`dehu_id`, `todays_date`, `work_order_uid`) VALUES
('a:3:{i:0;s:2:"14";i:', '2010-03-11 15:13:54', 634),
('a:4:{i:0;s:1:"8";i:1', '2010-03-11 15:59:12', 631),
('a:1:{i:0;s:1:"8";}', '2011-03-11 11:12:21', 634);

Open in new window

0
Comment
Question by:solunatec
2 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
Comment Utility
Your field is not big enough and is truncating the data. CHange it from

`dehu_id` varchar(20) NOT NULL,

to

`dehu_id` varchar(255) NOT NULL,
0
 

Author Closing Comment

by:solunatec
Comment Utility
exactly as you said. ..thanks..
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now