php - wordpress show unserialize data in a smart way -


in wordpress have stored data in database serialize method. have fetched data in array. code this

global $wpdb;  $results = wpdb->get_results("select * `table` `id` = 3");  foreach($results $result) {     echo '<pre>';         print_r($result);     echo '</pre>';  } 

this 1 getting me data this

array (     [0] => stdclass object         (             [id] => 1             [title] => a:3:{i:1;s:8:"test1";i:2;s:8:"test2";i:0;s:0:"test3";}             [page] => a:3:{i:1;s:3:"dsa";i:2;s:4:"dsds";i:0;s:0:"sdvdsvds";}         )  ) 

now want count values , want show values in listing. here can see have 3 values title , page. took title counter. made this

foreach($results $result) {     $count = count(unserialize($result->title)); // gave 3     for( $i = 0; $i<$count; $i++ ) {         echo '<li></li>'; // gave me 3 li's wanted     }  } 

now values title , page need again foreach , unserialize method. can kindly tell me nice , smart way show data title , words here(inside li's). suggestions , appreciable.

you appear 90% of way there, need show data.

global $wpdb; $results = wpdb->get_results( "select * `table` `id` = 3" );  foreach( $results $result ) {     $titles = unserialize($result->title);      foreach( $titles $title ) { // loop through         echo '<li>'. $title ."</li>\n";      } } 

i have removed call count, if it's used work out how may times loop through won't need it. can use foreach loop loop through items in array.

i added line break (\n) after every </li>, make generated markup little more readable.

i have added spaces after each opening parenthesis , before each closing, inline wordpress coding standard.


Comments

Post a Comment

Popular posts from this blog

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

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

android - Associate same looper with different threads -