Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to add 'unserialize' to my ouput

Posted on 2011-03-16
6
Medium Priority
?
215 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 2000 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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