-1
我是新來的,我是PHP5 OOP的新手。我創建了db類和相關函數connect(),disconnect(),select(),ecc。 我的問題和我的問題是簡單地從數組$ res(result)中提取數據,以便以OOP方式公開數據。在PHP5中使用OOP方式從數組中提取數據
<?php
include('../php/class/Database.php');
$db = new database();
$db->connect();
$db->select('post','*','post_category','post.Category = post_category.Id','Date DESC','0,10'); // Table name, Column Names, JOIN, WHERE conditions, ORDER BY conditions
$res = $db->getResult();
print_r($res);
$db->disconnect();
?>
$資源返回此字符串的print_r()函數:
Array ([0] => Array ([Id] => 1 [Category] => 1 [Title] => W3C Validation Web [Content] => [Source] => [Link] => [Date] => 2013-12-20 14:15:00 [Author] => Andrea Limoli [ShortDescription] => HTML [LongDescription] => HyperText Markup Language) [1] => Array ([Id] => 13 [Category] => 13 [Title] => The art of Typography [Content] => [Source] => [Link] => [Date] => 2013-12-18 00:00:00 [Author] => Andrea Limoli [ShortDescription] => Typography [LongDescription] => Typography))
此代碼的工作,但我有一個HTML網頁,我公開數據,我必須填寫在DIV這些數據。例如:
echo("<div>".$row[Title]."</div>");
我知道如何以這種方式公開數據,但我想知道在面向對象的方式暴露HTML頁面上的數據的最佳方式。
我的問題是:「我怎樣才能提取$資源數據和麪向對象的方式使用它
您可以在陣列的stdClass的轉換。 – DaGardner