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

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.

Member Avatar for rajarajan2017

Echo the result of $sql and check whether you get the records from the database. If not may be the query problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.