Solved

how to add 'unserialize' to my ouput

Posted on 2011-03-16
6
210 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
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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