2012-12-10 54 views
0

我需要做這個棘手的事情:10個項目以隨機方式選擇,一個項目爲真/假標準其餘九個項目呼應:kohana3.3:做find_all(){{第一個元素的標準},然後回覆其餘元素

$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

+0

請告訴我這種使用第一排的原因是什麼? – biakaveron

+0

第一行是其中的基本項目。 – Haradzieniec

回答

0

我不知道如果這是你需要做什麼:

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