Solved

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

Posted on 2011-03-11
2
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 35110476
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
ID: 35130350
exactly as you said. ..thanks..
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to dynamically set the form action using jQuery.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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