![](/img/trans.png)
[英]query a mysql table for rows that have the same month value and store as a php array for later use displaying them on a calendar
[英]PHP SQL Joomla store table with two columns into array and echo them later
所以我有一個包含兩列的簡單表。 該表稱為“ mytable”,列為“ product”和“ id”。 該表有大約12個條目。
$db = JFactory::getDbo();
$query = "SELECT * FROM mytable";
$db->setQuery($query);
$results = $db->loadObjectList();
因此,到目前為止,我已經成功查詢了,但是我想回調每一行的結果。 那就是我堅持的部分。 我需要將其存儲到數組中,以便以后可以進行一會兒循環將每一行吐出來。 我也無法在該代碼的下面回顯它。 這需要存儲在一個數組中,然后從另一個頁面中拉出,然后吐出每一行。 謝謝!
嘗試這個,
$db = JFactory::getDbo();
$query = "SELECT * FROM mytable";
$db->setQuery($query);
$results = $db->loadObjectList();
echo '<pre/>'
print_r($results);//the resulted array is already in this variable you can iterate it later with foreach loop.
用於循環和打印
foreach($results as $key=>$value){
echo 'Product-->'.$value->product;
echo 'ID-->'.$value->id;
}
檢查Joomla數據庫查詢以獲取更多詳細信息。
希望能幫助到你..
我會親自為您查詢使用更多最新的編碼標准,例如:
$db = JFactory::getDbo();
$query->select($db->quoteName('*'))
->from($db->quoteName('mytable'));
$db->setQuery($query);
$results = $db->loadObjectList();
然后,要獲得結果,請創建一個循環:
foreach($results as $result) {
echo 'ID = ' . $result->id;
echo 'Product = ' . $result->product;
}
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.