Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 11th, 2008, 06:42 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old July 28th, 2008, 08:05 PM
Registered User
 
Join Date: Jul 2008
Location: Leeds, , United Kingdom.
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




Reply With Quote
  #3 (permalink)  
Old November 15th, 2012, 09:19 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Location: India
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...
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:15 PM
Chapter 5 CMS extension yousaid BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 14 April 23rd, 2007 04: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 05: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 05: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 01:19 AM



All times are GMT -4. The time now is 04:25 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.