Jump to content

Recommended Posts

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>';
						}
					}
				}


?>
Link to comment
https://forums.phpfreaks.com/topic/297290-query-dont-work/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.