Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

738 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