I need this tricky thing to be done: 10 items to selected in a random manner, one item for true/false criteria and the rest nine items to echo :
我需要这个棘手的事情:以随机的方式选择10个项目,一个项目用于真/假标准,其余九个项目用于回应:
$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
}
The php framework I use here is Kohana3.3
我在这里使用的php框架是Kohana3.3
1 个解决方案
#1
0
I'm not sure if this is what you need to do:
我不确定这是否是你需要做的:
$first = TRUE
foreach ($items as $item)
{
if ($first)
{
$first = FALSE;
}
else
{
echo $item->name;
}
}
#1
0
I'm not sure if this is what you need to do:
我不确定这是否是你需要做的:
$first = TRUE
foreach ($items as $item)
{
if ($first)
{
$first = FALSE;
}
else
{
echo $item->name;
}
}