我在代码中使用$text =$product[0];和$time =$product[1];:
<?php
include("cache/phpfastcache.php");
phpFastCache::setup("storage","auto");
$cache = phpFastCache();
$products = $cache->get("product_page");
if($products == null) {
$akhbarkotah1 = $conn->prepare("SELECT text,time FROM small WHERE active='0' ORDER BY time DESC LIMIT 10");
$akhbarkotah1->execute();
$products = $akhbarkotah1->fetchAll();
$cache->set("product_page", $products,10);
}
foreach($products as $product){
$text =$product[0];
$time =$product[1];
?>
<a class="lastnews">
<div id="lastnews_title" class="YekanBlack10" style="width:585px;">
<div><?php echo $text; ?></div>
<div class="YekanRed10" style="text-align:left">
<?php echo timeTonow($time); ?>
</div>
<div style="border-bottom:2px solid #7c0000;height:5px;"></div>
</div>
</a>
<?php
}?>当将变量更改为
foreach($products as $product){
$text =$product->text;
$time =$product->time;不工作
问题出在哪里?
发布于 2014-03-05 00:23:33
更改以下内容:
$products = $akhbarkotah1->fetchAll();
$cache->set("product_page", $products,10);
}
foreach($products as $product){
$text =$product[0];
$time =$product[1];
?>至
$cache->set("product_page", $products,10);
}
foreach($product = $akhbarkotah1->fetch(PDO::FETCH_OBJ)) {
$text = $product->text;
$time = $product->time;
?>https://stackoverflow.com/questions/22176016
复制相似问题