Adauga separator dupa 3 Id-uri extrase

Cum adaug separator dupa fiecare 3 produse extrase din baza de date ?

exemplu : DEMO
Dupa fiecare 3 pizza , este adaugata o imagine ca separator…

Cum pot adauga si eu la fel ? dupa fiecare 3 produse !

<?php

$pizzaRows = array_chunk($pizzaFromDatabase, 3);

foreach ($pizzaRows as $threePizza) {
    foreach ($threePizza as $onePizza) {
        echo $onePizza['name'];
    }

   echo 'separator';
}

Ceva de genul, adaptezi tu…

2 Likes

Nu ma descurc deloc sa-l adaptez :expressionless: array_chunk($pizzaFromDatabase, 3) aici ce trebuie sa pun ?

query ?
$ pizzaFromDatabase = "SELECT * FROM products"

Folosesti vreun framework?

Nu !

     //get rows query
        $query = $db->query("SELECT * FROM products WHERE id = 1 OR id %5 = 1 ORDER BY id ASC LIMIT 200");
        if($query->num_rows > 0){ 
            while($row = $query->fetch_assoc()){
				
		$name = strtr($row["name"], '23', '  ');
		$name = trim($name);

Incearca $pizzaFromDatabase = $query->fetch_assoc();

$query = $db->query("SELECT * FROM products WHERE id = 1 OR id %5 = 1 ORDER BY id ASC LIMIT 200");
        if($query->num_rows > 0){ 
            $i = 1;
            while($row = $query->fetch_assoc()){
				
		$name = strtr($row["name"], '23', '  ');
		$name = trim($name);
                if($i % 3 == 0){
                     echo "<br />-----SEPARATOR-----<br />";
                }
               $i++;
            }
       }
1 Like

Multumesc mult de tot !

That logic is atrocious:

  • mixed views, sql, business logic, AAAAaaa …
  • where’s the pagination in there?
  • why are you mixing SQL with view logic?
  • use something like this as a helper in the views

This is the kind of stuff that will get you :fire:-ed

6 Likes