Solved

how to add 'unserialize' to my ouput

Posted on 2011-03-16
6
204 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
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
Comment Utility
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
Comment Utility
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
Comment Utility
$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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

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

Expert Comment

by:Rik-Legger
Comment Utility
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
Comment Utility
thank you...
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

763 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