PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 8, 2022

[FIXED] How to fetch recent 3 post from a blog table: magento

 July 08, 2022     blogs, database, magento, php, posts     No comments   

Issue

I have a table in database as "neotheme_blog_post" and there are many post in there, now i want to fetch recent 3 posts from this table and show them on home page: I have tried to fetch the data as follows but nothing worked:

    <?php $connection = 
      Mage::getSingleton('core/resource')->getConnection('core_read');
      $query      = "Select * FROM 'neotheme_blog_post'";
      $rows       = $connection->fetchAll($query);

      foreach ($rows as $values) {
      echo $name = $values['name'];

      }?>

Solution

In my case i get the three recent posts as like follows using neotheme blog extension:

     $connection = 
     Mage::getSingleton('core/resource')->getConnection('core_read');
     $query = "Select * FROM neotheme_blog_post ORDER BY created_at DESC LIMIT 3 ";
     $rows = $connection->fetchAll($query);
     foreach ($rows as $values) {
     $post_titile = $values['cms_identifier'];
     echo '<div>';
     echo '<h1>' . $name = $values['title'] . '</h1>';
     echo $summery = $values['summary'];
     echo '<a href="' . $this->getUrl().'blog/'.  $post_titile . '">Read More</a>';
      echo '</div>';


Answered By - Xabby
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing