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
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.