2014-09-10 1 views
0

워드 프레스에서 데이터를 저장하는 방법은 제목 [1], 두 번째 행 제목 [2], 세 번째 제목 [3] 등과 같이 첫 번째 행을 의미합니다. . 이 방법은 모든 필드 (이름, 전화)에 대해 동일합니다. 직렬화로 데이터를 저장 한 후 이제 데이터를 가져 오려고합니다. 그래서 가져 오기 위해이 스크립트를 가지고 있습니다. print_r ($ results); 나는 unserilize 사용이워드 프레스 데이터가 해당 순서대로 직렬화합니다.

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

    foreach($titles as $title) { 
     echo $title; 
    } 
} 

처럼 foreach는 한 데이터를 사용하려면이

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";} 

     ) 

) 

같은 결과를 얻고있다 그러나 이것은 내가 (ID, 제목 등의 모든 속성을 원하는 때문에 같은 의미를 doesnot 같은 행에 대해, 이름, 전화) 1 행은 그래서 누군가가 친절하게 어떻게 이렇게 말해 줄 수있는이

Id Title Name Phone 
4 title1 name1 123 
4 title2 name2 324 
4 title3 name3 648 

같이 표시해야합니다 데이터 element.so 1에 대한 모든 값을 표시한다는 뜻?

답변

0

이것은 각 배열에 같은 수의 항목이 있다고 가정합니다. ID도 사용할 수 없습니다.

<table> 
    <thead> 
     <tr> 
      <th>ID</td> 
      <th>Title</th> 
      <th>Name</th> 
      <th>Phone</th> 
     </tr> 
    </thead> 
    <tbody> 
<?php 
foreach($results as $result) { 
    $titles = unserialize($result->title); 
    $names = unserialize($result->name); 
    $phones = unserialize($result->phone); 

    $i=0; 
    foreach($titles as $title) { 
     echo "<tr>\n"; 
     echo " <td>4</td>\n"; // This isn't in your serialized data. I'll let you work out where it 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>