【问题标题】:kohana3.3 : do find_all() while {criteria for the 1st element} and echo the rest elements thereafterkohana3.3 :在 {第一个元素的标准} 时执行 find_all() 并在其后回显其余元素
【发布时间】:2012-12-10 18:41:34
【问题描述】:

我需要做这个棘手的事情:以随机方式选择 10 个项目,一个用于真/假标准的项目,其余 9 个要回显的项目:

$unique_items=array('bike', 'doll', 'carpet', 'postcard');

do {
   $items=ORM::factory('Shop')
     ->order_by(DB::expr('Rand()'))//this way I take 10 random rows from the table
     ->limit(10)
     ->find_all();
}while (in_array(first_item_from_ten_rows->name, $unique_items));

foreach ($items as $item){
   echo $item->name;//display 2nd, 3rd, ..., 10th items, without the first one
}

我这里使用的php框架是Kohana3.3

【问题讨论】:

  • 这样使用第一行的原因是什么?
  • 第一行是基本项。

标签: php foreach while-loop kohana kohana-3


【解决方案1】:

我不确定这是否是你需要做的:

$first = TRUE
foreach ($items as $item) 
{
   if ($first)
   {
      $first = FALSE;
   }
   else
   {
      echo $item->name;
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-10
    • 2014-12-16
    • 1970-01-01
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多