daGrevis Posted October 26, 2010 Report Posted October 26, 2010 Sveiki, Veidoju forumu, bet nesanāk gluži tā kā iecerēts. *blush* Tabula - board__categories: `id` int( 8 ) NOT NULL auto_increment, `name` varchar( 255 ) NOT NULL, PRIMARY KEY ( `id` ) Tabula - board__forums: `id` int( 8 ) NOT NULL auto_increment, `category_id` int( 8 ) NOT NULL, `name` varchar( 255 ) NOT NULL, `description` varchar( 255 ) NOT NULL, PRIMARY KEY ( `id` ) Tagad gribu to visu smuki izvadīt, domāju, ka izvadās kategorijas nosaukums, pēc tam attiecīgie forumi, kas tai "pieder". Bet kas nesanāk ar pieprasījumu. SELECT board__categories.name, board__forums.category_id, board__forums.name, board__forums.description FROM board__categories, board__forums print_r() izvada: Array( [0] => Ziņas [name] => iPoker.lv ziņas [1] => 1 [category_id] => 1 [2] => iPoker.lv ziņas [3] => Šajā sadaļā nonāk ziņas par iPoker.lv forumu. [description] => Šajā sadaļā nonāk ziņas par iPoker.lv forumu. ) Quote
daGrevis Posted October 26, 2010 Author Report Posted October 26, 2010 O! =) Pieprasījumu laikam sataisīju kā vajag! =) Bet tagad tikai, kā lai to pareizi izvada? Pieprasījums: SELECT board__categories.id, board__categories.name, board__forums.category_id, board__forums.name, board__forums.description FROM board__categories, board__forums WHERE board__categories.id = board__forums.category_id print_r(): Array ( [0] => 1 [id] => 1 [1] => Ziņas [name] => iPoker.lv ziņas [2] => 1 [category_id] => 1 [3] => iPoker.lv ziņas [4] => Šajā sadaļā nonāk ziņas par iPoker.lv forumu. [description] => Šajā sadaļā nonāk ziņas par iPoker.lv forumu. ) Quote
marcis Posted October 26, 2010 Report Posted October 26, 2010 (edited) Krč vienkārši loģika: $tmp = 0; $res = mysql_query("SELECT `c`.`id`, `c`.`name` AS `cname`, `f`.`name`, `f`.`description` FROM `board__categories` AS `c` JOIN `board__forums` AS `f` ON `f`.`category_id` = `c`.`id` ORDER BY `c`.`id` ASC"); while($row = mysql_fetch_object($res)){ if($row->id != $tmp) echo '<h1>',$row->cname,'</h1>'; // cita kategorija -> izvadam nosaukumu echo '<p>',$row->name,' <small>',$row->description,'</small></p>'; $tmp = $row->id; // nākamā ieraksta kategorija tiks salīdzināta ar šīs id } Edited October 26, 2010 by marcis Quote
daGrevis Posted October 26, 2010 Author Report Posted October 26, 2010 Viss strādā ideāli! Paldies. =)) Quote
daGrevis Posted October 29, 2010 Author Report Posted October 29, 2010 Tikko atradu bugu! xD Izvadot pietiekami daudz forumus veidojās nepareizs div'u izvadījums (interesants vārds). Ja nav daudz forumu, tad viss ir pareizi. Ja ir vairāk, tad lūk... PHP, kas izvada visu: while( $database = mysql_fetch_array( $query ) ) { if( $database['id'] !== $temporary_id ) { echo " <div class=\"category\"> <div class=\"name\"> <h3>{$database['cname']}<h3> </div> "; } echo ' <div class="forum"> <h4><a href="#">' . $database['name'] . '</a></h4> <p>' . parse__bb_codes( $database['description'] ) . '</p> </div> '; if( $database['id'] === $temporary_id ) { echo " </div> <br /> "; } $temporary_id = $database['id']; } CSS (2min rakstīju, tāpēc ir tāds, kāds ir): http://paste.php.lv/b509bcde201024b4ef95e732a8b3559d?lang=php ; Izvadītais HTML: http://paste.php.lv/d8b0e63bbda72acabccfed91423b41b5?lang=php . Quote
php newbie Posted October 29, 2010 Report Posted October 29, 2010 (edited) te mazliet nepareiza loģika varētu kaut kā tā $firstIteration = true; while( $database = mysql_fetch_array( $query ) ) { if( $database['id'] !== $temporary_id ) { // aizver ieprieksejo kategoriju, ja nav pirma iteracija if(!$firstIteration) { echo " </div> <br /> "; } // tad atver jaunu kategoriju echo " <div class=\"category\"> <div class=\"name\"> <h3>{$database['cname']}<h3> </div> "; } echo ' <div class="forum"> <h4><a href="#">' . $database['name'] . '</a></h4> <p>' . parse__bb_codes( $database['description'] ) . '</p> </div> '; $firstIteration = false; $temporary_id = $database['id']; } // aizver pedejo kategoriju echo " </div> <br /> "; Edited October 29, 2010 by php newbie Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.