Divs according to mysql result in a loop

JenniferW1998

New Member
First off, sorry if the title is confusing! I'm working on a part of a blog that determines how lists of recent posts (sometimes determined by a date) in a category are to be displayed. In the database, each category has a "type" set that determines whether the div it goes in is small or large.I can get the results to display but each link in the list has its own div, instead of being contained in one "main" category div.Shorter explanation:The database pulls results from the categories table and the posts table, as you can see in the query. The loop then runs so that the category boxes and the links in them can be created dynamically. The problem is that the divs, which are supposed to house a list of links, are instead wrapping around each individual link and not the set that is desired.While the code below shows only two "types", I had planned on adding more in the future.Here is the code\[code\] <? require("classes/Database.class.php"); $db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); $time = $_REQUEST['time']; $db->connect(); $sql = "SELECT cm.id, cm.title AS cmtitle, cm.sectionid, cm.type AS cmtype, cd.id, cd.time, cd.link, cd.title, cd.description, cd.sectionid AS sectionid FROM c_main AS cm JOIN c_data AS cd ON cd.sectionid=cm.sectionid WHERE cd.sectionid=cm.sectionid AND time = '".$time."' ORDER by id ASC"; $rows = $db->query($sql); while($record = $db->fetch_array($rows)){ //determine what div to use by checking "type" if ($record['cmtype'] == 'large') { ?> <div class="large" > <? } elseif ($record['cmtype'] == 'small') { ?> <div class="small"> <? } for($x =0; $x <= $db->affected_rows; ++$x) { if ($record['cmtype'] == 'small') { echo $record['title'].'<br/>'; } else { echo $record['title'].'<br/>'.$record['description']; } break; } echo '</div>'; } $db->close(); ?> \[/code\]Basically I am trying to have it like this:\[code\] /-------------------\ | Category Title | | -relevant link | | -relevant link | \____________________/ /-------------------\ | Category Title | | -relevant link | | -relevant link | \____________________/ .... and so on for each subsequent category\[/code\]And not this (which is how it's being outputted)\[code\]/-------------\\relevant link/ -------------/-------------\\relevant link/ ------------- etc.\[/code\]Here is the mysql wrapper I'm currently using, if that's of any significance http://ricocheting.com/scripts/php_mysql_wrapper.php
 
Back
Top