0

Hi,

I am trying to make a list of products with the product heading at the top. and trying to make it dynamic.

I have put a foreach() inside another foreach(), I have all the info in the database, however nothing is displaying. So I am stumped.???.

$sql = "SELECT * FROM products";
$setBrand=array();
foreach ($conn->query($sql) as $row) {   
$setBrand[]=<<<END
    <div class="brandRowM">
        <div class="brandRow">
            <div class="brand"><a href="#">$row[brand]</a></div><br />
            <div class="productSmPic">
                <ul>
END;
            $sql = "SELECT * FROM products WHERE top = 1 && brand = '".$row['brand']."'";
            $setInfo=array();
            foreach ($conn->query($sql) as $info) {   
            $setInfo[]=<<<END
                    <li><a href="product.php"><img src="$info[PFN1]" width="100px" height="60px" /></a>
                        <ul>
                            <li><div class="productSmName">$info[name]</div></li>
                            <li><div class="productSmCode">$info[icode]</div></li>
                            <li><div class="productSmRRP">RRP: $$info[RRP]</div></li>
                            <li><div class="productSmQRP">Click to see price</div></li>
                        </ul>
                    </li>
END;
            }
            $setInfo=implode("\r\n",$setInfo);

<<<END
                </ul>    
            </div>        
        </div>
    </div>
END;
    }
    $setBrand=implode("\r\n",$setBrand);

I have been trying to get this to work for (seems like forever), any help would be sooooo appreciated.

Thanks

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by rajarajan2017
0

your $sql query and return resultset is same for both foreach.so it is little bit ambiguous.
Post ur requirement, so anyone can give you logic.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.