0
我從JSON對象網站獲取數據,我會告訴它在表 作爲最後的圖像(檢查底部),但我真的luckNumber和產品名稱複雜,因爲我將爲此表創建5列,並向每個繪製類型插入值。如何使用PHP在Foreach中生成表列?
這裏是JSON數據
object(stdClass)[5]
public 'luckNumber' => string '78087' (length=5)
public 'productJson' =>
object(stdClass)[4]
public 'luckDrawDesc' => string 'DRAW3' (length=5)
public 'validPeriod' => int 2
public 'productName' => string 'DRAW3' (length=5)
object(stdClass)[5]
public 'luckNumber' => string '78087' (length=5)
public 'productJson' =>
object(stdClass)[4]
public 'luckDrawDesc' => string 'DRAW4' (length=5)
public 'validPeriod' => int 2
public 'productName' => string 'DRAW4' (length=5)
object(stdClass)[5]
public 'luckNumber' => string '78087' (length=5)
public 'productJson' =>
object(stdClass)[4]
public 'luckDrawDesc' => string 'DRAW3' (length=5)
public 'validPeriod' => int 2
public 'productName' => string 'DRAW3' (length=5)
object(stdClass)[3]
public 'luckNumber' => string '78087' (length=5)
public 'productJson' =>
object(stdClass)[2]
public 'luckDrawDesc' => string 'DRAW2' (length=5)
public 'validPeriod' => int 2
public 'productName' => string 'DRAW2' (length=5)
object(stdClass)[1]
public 'luckNumber' => string '78087' (length=5)
public 'productJson' =>
object(stdClass)[0]
public 'luckDrawDesc' => string 'DRAW1' (length=5)
public 'validPeriod' => int 2
public 'productName' => string 'DRAW1' (length=5)
這是PHP功能,以選擇所有的數據,並生成表
功能描述:
luckNumber內含一百米運動員值取決於產品名稱(DRAW1,DRAW2,DRAW3,DRAW14)。
public function det_data() {
$c_arr = json_decode($this->urlData);
$i = 0;
$html = '<table>';
$html .= '<thead>';
$html .= '<th>Date</th>';
$html .= '<th>Draw1</th>';
$html .= '<th>Draw2</th>';
$html .= '<th>Draw3</th>';
$html .= '<th>Draw4</th>';
$html .= '</thead>';
$html .='<tbody>';
foreach ($c_arr as $items) {
if ($i == 30)
break;
{
$html .= '<tr>';
if ($items->productName =='DRAW1') {
$html .= '<td>' . $items->createTime . '</td>';
$html .= '<td>' . $items->luckNumber . '</td>';
}
if ($items->productName =='DRAW2') {
$html .= '<td>' . $items->luckNumber. '</td>';
}
if ($items->productName =='DRAW3') {
$html .= '<td>' . $items->luckNumber. '</td>';
}
if ($items->productName =='DRAW4') {
$html .= '<td>' . $items->luckNumber. '</td>';
}
$html .= '</tr>';
$i++;
}
}
$html .='</tbody>';
$html .= '</table>';
return $html;
}
我想作爲上述圖像 –
你應該 - 在某種程度上,這有什麼不同? –