Link to home
Start Free TrialLog in
Avatar of solunatec
solunatec

asked on

how to add 'unserialize' to my ouput

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

Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

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.
Avatar of solunatec
solunatec

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you I got it to work but doesnt look very nice...any ideas.
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...
thank you...