Jump to content

displaying top 5 items


KevHopwood

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

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.