列表中的随机产品

时间:2012-09-17 18:57:23

标签: php list loops random

  

可能重复:
  php loop random product from the list

我需要产品清单,从女巫我可以随机显示4个项目。

我曾尝试编写PHP代码,但需要帮助完成语法和变量。

<?php 

// my product list
function productlistX {
    $array = array( 

        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};
        $product {$name = 'product name', $link = 'product link', $img = "product image"};

    )

    // need to display 4 random products from the array above 
    foreach  {
        echo "<li>".$name . $link . $img . "</li>"
    }
}

// display these random products in my ajax tab (products.php?order=mytab)
$data['mytab'] = $productlistX;

if (isset($data[$_GET['order']])) { 
    echo $data[$_GET['order']];
} 
?>

提前感谢!

0 个答案:

没有答案