PHP - 根据id_product在菜单项中插入特定类

时间:2015-03-26 13:22:39

标签: php css class

我是一个PHP新手并且知之甚少,但我需要为每个菜单项插入一个特定的类。 我的想法是重复使用' id_product'作为一个班级,但它到目前为止还没有工作! 这是代码的一部分:

    //Show the content of each menu
$SecondMenu      = $PDO->queryFetchAllAssoc("SELECT * FROM product WHERE sub_category_id='".$titleSecondMenu['id_sub_category']."' ORDER BY `id_product`");
//echo "SELECT * FROM product WHERE sub_category_id=".$rowTitleSecondMenu['id_sub_category']." ORDER BY sub_category_id, id_product";
if($subCatId!=$titleSecondMenu['id_sub_category'])
{
    $style = ' style="display:none;"';
}
else
{
    $style = '';
}

echo '<div id="div'.$titleSecondMenu['id_sub_category'].'"'.$style.'>'."\r";
foreach($SecondMenu as $rowSecondMenu)
{
    //echo $prodId.' '.$rowSecondMenu['id_product'].' <br />';
    //echo $subCatId.' '.$rowSecondMenu['sub_category_id'].' <br />';


    if($prodId==$rowSecondMenu['id_product'] && $subCatId==$rowSecondMenu['sub_category_id'])
    {
        $class = 'Selected';
        $color = '';
    }
    else
    {
        $class = 'Unselected';
        $color = 'color:#5c5c5c;';
    }
    //echo 'c='.$catId.'&amp;sc='.$rowSecondMenu['sub_category_id'].'&amp;p='.$rowSecondMenu['id_product'];
    switch ('c='.$catId.'&sc='.$rowSecondMenu['sub_category_id'].'&p='.$rowSecondMenu['id_product']) {

        case "c=1&sc=1&p=1":
            $url_fr = "/engraisprintemps/bio-arbres";
            $url_en = "/springfertilizers/bio-trees";
            break;

        case "c=1&sc=1&p=2":
            $url_fr = "/engraisprintemps/bio-cedres";
            $url_en = "/springfertilizers/bio-cedars";
            break;

0 个答案:

没有答案