Solved

how to add 'unserialize' to my ouput

Posted on 2011-03-16
6
214 Views
Last Modified: 2012-05-11
I have the following script going and its working fine but I have information in the dehu_id field that is an array..I am trying to figure out how to create 'unserialize'in my output...after the echo command..if this is doable or do I have to take a different approach?
$query2="SELECT account_name, site_address, site_city, site_state, dehu_id
FROM accounts_table AS a, acitve_sites_table AS ac, wo_stats AS w, dehu_status AS d
WHERE a.account_uid = ac.account_id
AND w.active_sites_uid = ac.active_sites_uid
AND d.work_order_uid = w.work_order_uid
AND wo_status_codes =1";
 

  $result2 = $db->query($query2);

  $num_results2 = $result2->num_rows;

  echo "<p>Number of dehus found: ".$num_results2."</p>";

  for ($i=0; $i <$num_results2; $i++) {
     $row = $result2->fetch_assoc();
     echo "<p class=alt /> company name:<strong>" ;
     echo htmlspecialchars(stripslashes($row['account_name']));
     echo "</strong>;
      <br  />address: ";
     echo stripslashes($row['site_address']);
     echo "<br  />city: ";
     echo stripslashes($row['site_city']);
     echo "<br />state: ";
     echo stripslashes($row['state_state']);
     echo "</strong><br />zip: ";
     echo stripslashes($row['zip']);
     echo "</strong><br />dehus: ";
     echo stripslashes($row['dehu_id']);
     echo "</p>"; 
     
 
  };

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
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35147849
Did you put the value in with serialize()? And does it contain only that serialized string?
Because ifso than unserialize($row['dehu_id']) should work and you could fetch the array with its normal name (var_dump($array_name);).
If not, it would help me to see what you inputted and tell me how you excactly want to output it on the screen.
0
 

Author Comment

by:solunatec
ID: 35148315
If I do this:
 echo  unserialize($row['dehu_id']);
for output I simply get :
Array..
if I do :
echo  stripslashes($row['dehu_id']);
I get:
dehus: a:3:{i:0;s:11:"DrizAir2400";i:1;s:7:"EvoLGR1";i:2;s:7:"EvoLGR2";}

this is how the information looks in mysql:

a:3:{i:0;s:11:"DrizAir2400";i:1;s:7:"EvoLGR1";i:2;s:7:"EvoLGR2";}
so it looks accurate to the field...
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35148360
$string = 'a:3:{i:0;s:11:"DrizAir2400";i:1;s:7:"EvoLGR1";i:2;s:7:"EvoLGR2";}'; /* The information out your database) */
$array = unserialize($string); /* Unserialize the string into a variable called $array */
echo '<pre>'.print_r($array,1).'</pre>'; /* See the results */

Open in new window


That example will output:

Array
(
    [0] => DrizAir2400
    [1] => EvoLGR1
    [2] => EvoLGR2
)

Open in new window


0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:solunatec
ID: 35158369
thank you I got it to work but doesnt look very nice...any ideas.
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35158412
If you put serialized arrays in your database you won't get it nicer than this,
but i don't really see the 'ugliness' in this...
0
 

Author Comment

by:solunatec
ID: 35158574
thank you...
0

Featured Post

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

622 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