Jump to content

Recommended Posts

I have 1 table called article, and another called articlecategory. They are linked through a field called articlecategoryid. To display the results in the front end I am creating an SQL statement for each article category like:

 

SELECT * from articles and articlecategory WHERE articlecategoryid both = international news

 

and then another for the next articlecategory:

 

SELECT * from articles and articlecategory WHERE articlecategoryid both = local news

 

and so on.

 

I know this is the wrong way to do it, and if an administrator adds a new articlecategory, then it obviously wont show up because each articlecategory is hand coded in.

 

What is the correct way to do this, so it will cycle through each articlecategory and add the latest story underneath the title for each like this:

 

Articlecategory Title 1

Latest story for articlecategory title 1

 

Articlecategory Title 2

Latest story for articlecategory title 2

 

Articlecategory Title 3

Latest story for articlecategory title 3

 

And so on..

 

Some articlecategory's may not have any related stories .

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/87168-title-and-content-from-2-tables/
Share on other sites

heres ex..on how to join

 

SELECT * from articles
INNER JOIN articlecategory on articlecategory.articlecategoryid  = articles.articlecategoryid 
WHERE both = international news

syntax...
select (columns) from table1 
inner join table2 on table1.field = table2.fields
where etc..
and etc.. 

hope that helps

Thanks, thats great. However this will only give the results for 1 category i.e. International News. How can I cycle through all differant categories, with 1 news for each category like this:

 

Articlecategory Title 1

Latest story for articlecategory title 1

 

Articlecategory Title 2

Latest story for articlecategory title 2

 

Articlecategory Title 3

Latest story for articlecategory title 3

 

Thanks.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.