Jump to content

displaying top 5 items


Go to solution Solved by vinny42,

Recommended Posts

Sorry I'm not the best at PHP but I'm learning.

 

I'm creating my website and am creating a page called more.

Within this page I want to add a list of my top 5 promotions on my site. Each promotion is saved in my mobi database in mysql and I have added a count for each time someone views a particular promotion on my single.php page.

So basically. What I need to do is display 5 promotions with the highest number in the "views" field in my mobi database.

I currently have these codes:

include_once('include/connection.php');
include_once('include/article.php');

and

<?php foreach ($articles as $article) { ?>

<a href="list.php?id=<?php echo $article['promo_title']; ?>">
<?php echo $article['promo_title']; ?>
</a>

in more.php and also

class views {
public function fetch_all(){
global $pdo;

$query = $pdo->prepare("SELECT * FROM mobi ORDER BY views DESC LIMIT 0, 5");
$query->execute();

return $query->fetch(); 

}

}

in articles.php which only loads some weird text of "t t t t h h w w d d d d 3 3"

 

what more will I need to add to get this to work?

 

thank you.

Link to comment
https://forums.phpfreaks.com/topic/282081-displaying-top-5-items/
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.