Hi,
I don't know what amI do wrong.
I have 3 tables, (authors, text, kategories). I want to print every group names from database and + 3 text below kategory name. After first record (text) separately two more (next) records. With this code I give only the first category with 3 text...
Please if You can help me....
<?php
/* SELECT FROM DATABASE */
$QuerySelect = ' SELECT
c_kat.c_kat_onoff,
c_kat.c_kat_delete,
c_kat.c_kat_order,
c_autor.c_autor_onoff,
c_autor.c_autor_delete,
c_autor.c_autor_prezime,
c_autor.c_autor_ime,
c_autor.c_autor_id,
c_kat.c_kat_id,
c_kat.c_kat_ime,
c_vesti.c_vesti_id,
c_vesti.c_vesti_date,
c_vesti.c_vesti_sat,
c_vesti.c_vesti_min,
c_vesti.c_vesti_naslov,
c_vesti.c_vesti_text,
c_vesti.c_vesti_kat,
c_vesti.c_vesti_autor,
c_vesti.c_vesti_onoff,
c_vesti.c_vesti_delete
FROM
c_vesti
INNER JOIN c_kat ON c_kat.c_kat_id = c_vesti.c_vesti_kat
INNER JOIN c_autor ON c_autor.c_autor_id = c_vesti.c_vesti_autor
WHERE `c_vesti_onoff` = 1 AND `c_vesti_delete` = 0
ORDER BY `c_kat_order` ASC, `c_vesti_date` DESC, `c_vesti_sat` DESC, `c_vesti_min` DESC, `c_vesti_id` ASC LIMIT 3 ';
$query_select = mysqli_query($dbConnect, $QuerySelect) or die (mysqli_error($dbConnect));
if(!$query_select){ echo mysqli_error($dbConnect); exit; }
while($request = mysqli_fetch_array($query_select)) {
$group_by_cat[$request['c_kat_ime']][] = $request;
}
foreach($group_by_cat as $group => $rows) {
echo '<div class="catcolor">' . $group . '</div>'; // Category name
$first_rec = true;
foreach($rows as $row) {
if ($first_rec) {
// first record
echo '<div>First text headline - ', $row['c_vesti_naslov'], '</div>';
$first_rec = false;
} else {
// other records
echo '<div>Other text headline -', $row['c_vesti_naslov'], '</div>';
}
}
}
?>