Working with two tables

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by 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
Close
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
Close
where could I add this line?
 
0
Close
Where you fetch the articles !!! :p
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Search: choose where to search from the All tab
Open the search at the top of any page. On the All tab, the list next to the search box lets you choose where to search: everything, all...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back