Unstoppable Domains

Working with two tables

Spaceship Spaceship
Watch

asgsoft

VIP Member
Impact
9
Hey everyone

I am stuck again :D

This time I'm trying to work with two tables.

First one is a categories one
Second one is an articles one

The category one has the ability to have categories and sub cats too.

So basically I want to list the articles from the article database which have a value of say x for their cat_id field to be listed under their appropriate heading.

So the structure looks a bit like this:
Cat
Article
Sub Cat
article
article

Here is the code which just lists the category titles. I couldn't go on from there :S

PHP:
$sql = "SELECT * FROM categories WHERE ParentID = 0 AND id = $id";
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res))
{
     
	 
	 // if link empty echo cat page else echo link
	 
	 echo "<dt>$row[name]</dt>";
//echo articles under man cat
     $sql_sub = "SELECT * FROM categories WHERE ParentID = ".$row["id"];
	 //echo $sql_sub;
     $res_sub = mysql_query($sql_sub);
     while ($row_sub = mysql_fetch_assoc($res_sub))
     {
          echo "<dd>$row_sub[name]</dd>";
		  //echo articles under subcat
     }
}


any help would be greatly appreciated :D
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You need to run a mysql query to get the article information, using a specific value.
(In your case the category ID.)
PHP:
@mysql_query("SELECT ArticleName,ArticleContent,ArticleAuthor,ArticleComments,ArticleData FROM `articles` WHERE `ArticleCat`='$row[cat_id]'");
 
0
•••
where could I add this line?
 
0
•••
Where you fetch the articles !!! :p
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back