Solved

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

Posted on 2011-03-11
2
323 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

816 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

9 Experts available now in Live!

Get 1:1 Help Now