PDA

View Full Version : Help with Dynamically creating category list


krohnathlonman
Sat 17th Apr '04, 9:42pm
This is for my article system that I'm preparing to release.... I just can't seem to grab the data and cycle through the lists properly


$cathandle = mysql_query("SELECT * FROM amartincats ORDER BY id ASC");

$count = mysql_num_rows($cathandle);
while($count>0)
{
$catdata = mysql_fetch_array($cathandle);//get category data
$catstitle = $catdata[name];

//loop through articles of given category
$ahandle = mysql_query("SELECT id, subject, subject_2 FROM amartin WHERE category = '".$catdata[id]."' ORDER BY subject ASC");
$acount = mysql_num_rows($ahandle);
while($acount>0)
{
$adata = mysql_fetch_array($ahandle);

$populars['subject'] = $adata[subject];
$populars['id'] = $adata[id];
$populars['subject_2'] = $adata[subject_2];


$acount--;
}//end article loop

eval("\$cats1bit .= \"".fetch_template('article_list_bit')."\";");
//echo($cats1bit); //do whatever has to be done to put in in the template :)
unset($cats1bit);

$count--;

eval("\$article[cat1] .= \"".fetch_template('article_cat1')."\";");
}
//end main cat loop

sirspot
Sun 18th Apr '04, 12:11pm
Are you receiving an error? If so, what is the error? If not, what is the actual end result you are trying to achieve given the data stored in your two tables? Is the id value of the first table being correctly stored in the second table?

krohnathlonman
Sun 18th Apr '04, 10:04pm
here's what I'm trying to do...

http://iamnotageek.com/articles.php

I need to grab the category ID's and the name of the category from one table THEN pull the headline and create a link which is in another table.

eXplosive
Sun 18th Apr '04, 11:39pm
I rewrote your code above. Please try this out.

<?php

$category_result = mysql_query('SELECT * FROM amartincats ORDER BY id ASC');

while($category = mysql_fetch_assoc($category_result))
{
$catstitle = $category['title'];

eval('$cats1bit .= "' . fetch_template('article_list_bit') . '";');

$article_result = mysql_query('SELECT id, subject, subject_2 FROM amartin WHERE category = ' . $category['id'] . ' ORDER BY subject ASC');

while ($article = mysql_fetch_assoc($article_result))
{
$populars['subject'] = $article['subject'];
$populars['id'] = $article['id'];
$populars['subject_2'] = $article['subject_2'];

eval('$article[cat1] .= "' . fetch_template('article_cat1') . '";');
}
}

?>