Jump to content

'views' row from multiple tables


dachshund

Recommended Posts

Hi,

 

I'm currently trying to give a list of the five most viewed pages on my website.

 

There are 3 main areas on the site - interviews, features and reviews.

 

Currently I have a 'most viewed' section for each one individually.

 

Which for interviews, looks like this.

 

<?php
$today = date('Y-m-d');
$sql="SELECT * FROM interviews ORDER BY views DESC LIMIT 5";
$result=mysql_query($sql);
?>

 

But now I want to combine all the tables (interviews, features, reviews). There is a row called 'views' in each.

 

I hope that makes sense.

 

Can anyone help?

 

Link to comment
https://forums.phpfreaks.com/topic/164862-views-row-from-multiple-tables/
Share on other sites

tables:

interviews

features

reviews

 

fields in each of these tables:

id, title, information, content, image, link, type, wordsby, VIEWS

 

If all of those tables have the same schema...why don't you just put them all in one table

 

like ....

 

articles

id, title, information, content, image, link, type, wordsby, VIEWS, article_type

 

where article_type could be the......well....article type.... interview, feature, or review.

 

Or you could use numbered values

where article_type could be like 0 for interview, 1 for feature, 2 for review, etc,etc,etc

what are the advantages of having it all in one table (other than having views all in the same place)?

 

well for one....it's less complicated and you don't need a JOIN for every single thing.

you can easily select all the interviews, reviews, or features with a WHERE clause.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.