I’m having a simple problem understanding how to parse stdObject returns from simple queries with mysqli … I’ve tried a couple of different ways to turn the stdObject into an array and also just using fetch_object() like here:
$cart_q = "SELECT card_name FROM products WHERE product_cat = 'HPC' LIMIT 12";
$result = $mysqli->query($cart_q);
echo "<table>";
$i = 0;
while ($products = $result->fetch_object()) {
if($i == 0)
echo "<tr>";
echo "<td>". $products->card_name ."</td>";
$i++;
if($i == 3) {
echo "</tr>";
$i=0;
}
}
echo "<table>";
I’ve done a print_r of the object and gotten an associative array, but breaking it down to dislay within a page has yet to work … any ideas?
Note: I actually think your problem is with iterating over the result array, thus label should be php, or /and HTML, but let’s see:
Its usually good to separate retriving records from presentation, for example like this:
Above will create array
$card_names => array('card_name1', 'card_name2' ... etc)Now, you can use foreach to iterate over that array and create output HTML. From what I’ve understood you want to create HTML table with 4 cells per row and one card name per cell.