?
Solved

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

Posted on 2011-03-11
2
Medium Priority
?
334 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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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