Wrox Programmer Forums
|
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2008, 05:42 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 13 - CMS

Hi all, I'm working on the CMS chapter and I've got it working perfectly, however is there a way which I can control the number of published arcticles that show up on the home page. At the moment it's unlimited and only shows the first few lines of a published article. I only want to show the title of the article and perhaps only the last four published.

here's the code

<?php
require_once 'conn.php';
require_once 'outputfunctions.php';


$sql = "SELECT article_id FROM cms_articles WHERE is_published=1 " .
       "ORDER BY date_published DESC";

$result = mysql_query($sql, $conn);

if (mysql_num_rows($result) == 0) {
  echo " <br><h5>";
  echo " There are currently no articles to view.<h5>";
} else {
  while ($row = mysql_fetch_array($result)) {
    outputStory($row['article_id'], TRUE);
  }
}


?>

Any advice would be cool, thanks in advance

 
Old July 28th, 2008, 07:05 PM
Registered User
 
Join Date: Jul 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

There are a few ways in which you can do this: -

1) Place a variable before the while loop (e.g. $i) and have it so the variable counts up by one each loop. Then, just set your maximum number of articles and when it reaches that number, just break from the loop.

e.g.

if (mysql_num_rows($result) == 0) {
  echo " <br><h5>";
  echo " There are currently no articles to view.<h5>";
} else {
$i=0;
  while ($row = mysql_fetch_array($result)) {
    $i++;
    outputStory($row['article_id'], TRUE);
    if ($i==5) break;
  }
}

2) Place a limit in your query

e.g.

$limit=5;
$sql = "SELECT article_id FROM cms_articles WHERE is_published=1 " .
       "ORDER BY date_published DESC LIMIT 1,$limit";

If you want to show the total number of articles, you need to modify the SQL code to this: -

$limit=5;
$sql = "SELECT SQL_CALC_FOUND_ROWS article_id FROM cms_articles WHERE is_published=1 " .
       "ORDER BY date_published DESC LIMIT 1,$limit";
$result = mysql_query($sql, $conn);

$sql2 = "SELECT FOUND_ROWS()";
$result2 = mysql_query($sql2, $conn);
$row2 = mysql_fetch_array($result2);
$numrows = $row2['0'];

The first method will be easier to integrate and is much easier to understand!

Hope this helps




 
Old November 15th, 2012, 09:19 AM
Registered User
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, it worked fine, but if I want to display 10 on index page and rest of the article is paginated....how can I do that...





Similar Threads
Thread Thread Starter Forum Replies Last Post
CMS Envelope problem chapter 9 luke.koziol BOOK: Beginning Cryptography with Java 1 May 6th, 2007 05:15 PM
Chapter 5 CMS extension yousaid BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 14 April 23rd, 2007 03:34 PM
problems with chapter 13 cms cyclonic BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 5 March 16th, 2007 04:25 AM
CMS (chapter 13) website integration nick.kirby BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 August 3rd, 2006 04:33 AM
Problems with chapter 13 cms hooligan BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 6 July 24th, 2005 12:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.