displaying data pulled from db ???
Posted: Fri Feb 11, 2005 7:57 pm
I wrote the function below to query the db to select all categories and their respective links then spit them out. The problem I'm having is figuring out a way to tell when a category is 'out of links' and it moves on to the next category.
As you can see I wrap everything in a table and when a category has no more links to display and when it moves on to the next category (and a new table cell) it's missing the '</td>' tag.
Am I going to have to use another query somehow or could I do something like
Thanks
As you can see I wrap everything in a table and when a category has no more links to display and when it moves on to the next category (and a new table cell) it's missing the '</td>' tag.
Code: Select all
function catsWithLinks()
{
$query = "select lc.catid, lc.cat_name, l.name, l.link_url from link_cat as lc, links as l
where l.catid = lc.catid order by lc.cat_name asc, l.name asc";
$result = @mysql_query($query);
$cat='';
$cats = '<table border=0 cellpadding=2 cellspacing=12><tr>';
while($row = mysql_fetch_array($result))
{
if($rowї"cat_name"] != $cat)
{
$cat = $rowї"cat_name"];
$id = $rowї"catid"];
$cats .= '<td valign=top class=mediumbold>' .strtoupper($cat). '';
}
$link = $rowї"name"];
$address = $rowї"link_url"];
$cats .= '<br><a href=' .$address. '>' .$link. '</a>';
}
$cats .= '</td></tr></table>';
return $cats;
}Code: Select all
if(no more links for this category){
$cats .= '<br><a href=' .$address. '>' .$link. '</a></td>';
}
else{
$cats .= '<br><a href=' .$address. '>' .$link. '</a>';
}