php - wordpress data serialize in corresponding order -


in wordpress have stored data serialize method means title 1st row named title[1], 2nd row title[2] , 3rd title[3] , on. method same fields(name,phone). after storing data serialize want fetch data. fetch have script this

$results = $wpdb->get_results("select * `table` `id` = 4"); 

now when doing print_r($results); getting result this

array (     [0] => stdclass object         (             [id] => 4             [title] => a:3:{i:1;s:8:"title1";i:2;s:8:"title2";i:0;s:0:"title3";}             [name] => a:3:{i:1;s:8:"name1";i:2;s:8:"name2";i:0;s:0:"name3";}             [phone] => a:3:{i:1;s:8:"123";i:2;s:8:"324";i:0;s:0:"648";}          )  ) 

to use data have used unserilize , foreach this

foreach($results $result) {     $titles = unserialize($result->title);     $names = unserialize($result->name);     $phones = unserialize($result->phone);      foreach($titles $title) {         echo $title;     } } 

but doesnot make sense because want attributes (id, title, name, phone) same row means 1st row should show values 1st element.so data should show this

id  title    name    phone 4   title1   name1   123 4   title2   name2   324 4   title3   name3   648 

so can kindly tell me how this?

this assuming same number of items in each array. id isn't available.

<table>     <thead>         <tr>             <th>id</td>             <th>title</th>             <th>name</th>             <th>phone</th>         </tr>     </thead>     <tbody> <?php    foreach($results $result) {     $titles = unserialize($result->title);     $names = unserialize($result->name);     $phones = unserialize($result->phone);      $i=0;     foreach($titles $title) {         echo "<tr>\n";         echo "  <td>4</td>\n"; // isn't in serialized data.  i'll let work out comes from.         echo '  <td>'. $titles[$i] .'</td>'. "\n";         echo '  <td>'. $names[$i] .'</td>'. "\n";         echo '  <td>'. $phones[$i] .'</td>'. "\n";         echo "</tr>\n";          $i++;     } } ?>     </tbody> </table> 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -