false Posted December 21, 2009 Report Share Posted December 21, 2009 (edited) Tatad dātubāze `foruma_nosaukumi` izskatas šadi `id` int(11) NOT NULL AUTO_INCREMENT, `nos` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=11 ; Dātubāze `forumi` izskatas šadi `id` int(11) NOT NULL AUTO_INCREMENT, `nosaukums` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `paskaidrojums` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `f_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=11 ; Kāds var palīdzet parveidot kodu lai katrs forums stāvetu zem konkrēta nosaukuma id. Pats kods <div id="forums"> <?php $select_f = mysql_query("SELECT * FROM foruma_nosaukumi") or die(mysql_error()); while($f = mysql_fetch_array($select_f)){ $select_ff = mysql_query("SELECT * FROM forumi WHERE f_id = '".$f['id']."'") or die(mysql_error()); while($ff = mysql_fetch_array($select_ff)){ ?> <div class="border"><div class="title"> <?php echo $f['nos']; ?></div><table class="ipbtable" cellspacing="1"> <tbody><tr> <td class="head" width="66%">Forumi</td> <td class="head" style="text-align: center;" width="7%">Temati</td> <td class="head" style="text-align: center;" width="7%">Atbildes</td> <td class="head" width="35%">Pēdējā tēma</td></tr> <tr style="border-bottom: 1px solid rgb(255, 255, 255);"> <td class="row2"> <b><a href="/forum/?id=<?php echo $ff['id']; ?>"><?php echo $ff['nosaukums']; ?></a></b><br> <span style="color: rgb(102, 102, 102); font-size: 10px; font-family: tahoma;"><?php echo $ff['paskaidrojums']; ?></span> </td> <td class="row1" style="border-left: 1px solid rgb(255, 255, 255);" align="center">1</td> <td class="row1" style="border-left: 1px solid rgb(255, 255, 255);" align="center">2</td> <td class="row1" style="border-left: 1px solid rgb(255, 255, 255); height: 50px;" nowrap="nowrap"> Tēma: <b><a href="">adsadsasd</a></b><br/><small>Atbildes <b>42</b> Autors <b>false</b></small></td></tr></table></div><br> <?php }} ?> <br></div> Problēma ir tāda kā viņš izvēlk foruma nosaukumus un zem katra nosaukuma liek pa vienam forumam, pat ja tā id nesakrīt. Piemēram db `forumi` ir šadi ieraksti id, `nosaukums`, `paskaidrojums`, `f_id` 1, 'test', 'tralallala', '1' 2, 'test2', 'tralallala2', '2' 3, 'test3', 'tralallala3', '1' Viņš to test ieliek zem foruma nosaukuma ar id 1, test2 zem id 2, test3 zem id 3 Edited December 21, 2009 by false Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted December 21, 2009 Report Share Posted December 21, 2009 Tas ko tev vajag izmantot ir JOIN (INNER JOIN) - http://dev.mysql.com/doc/refman/5.0/en/join.html Izlasi kas tur rakstīts un kā to izmantot. Ja nesaproti, tad raksti ko tieši un ko esi uzrakstījis... Quote Link to comment Share on other sites More sharing options...
anonīms Posted December 21, 2009 Report Share Posted December 21, 2009 rATRIJS, a bez JOIN nevar? false, © mwcups kods (tik novāc lieko) - http://paste.php.lv/3f18ec52bf50d0b83cc80ab27df0ad12/nonum Quote Link to comment Share on other sites More sharing options...
false Posted December 21, 2009 Author Report Share Posted December 21, 2009 Liels paldies Tev! Quote Link to comment Share on other sites More sharing options...
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.