Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 August 9th, 2004, 04:22 PM
Friend of Wrox
 
Join Date: Jun 2004
Location: Fairfield, Iowa, USA.
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just looked on your phpinfo and your mysql version seems to be 3.23.58. Update mysql and your problem should go away.

Christian

 
Old August 9th, 2004, 04:34 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Me again!
Sorry! I was a bit too fast on the keyboard!

I didn't think about the mySQL version.
I'll try to find out!

 
Old August 9th, 2004, 04:40 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Christian,
I didn't think to look for it there!
I looked through it and found it!
I'll try and upgrade it.

 
Old August 10th, 2004, 08:58 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am running mySQL version 3.23.58 and as I'm on a shared server I can't get it upgraded just yet.
I have been experimenting with a count function to overcome the SELECT SQL_CALC_FOUND_ROWS but it's not very good.

Can any one suggest a work-around to overcome SELECT SQL_CALC_FOUND_ROWS on mySQL 3.23.58?

 
Old August 12th, 2004, 12:53 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK! I've managed to rewrite the code for viewforum.php and functions.php, which were both creating errors when they tried to invoke SELECT SQL_CALC_FOUND_ROWS, FOUND_ROWS() and JOIN when using mySQL versions older than 4.0.

If you are running an older version of mySQL like myself you might want to try these code fixes. I think they are working fine! But then, I never managed to get the original ones working! So I don't know.

Try them, and if you find a problem or a better way to do it please post it here.

First, lets alter functions.php
In function showTopic()

Replace:
Code:
  $sql = "SELECT SQL_CALC_FOUND_ROWS ".
           "p.id, p.subject, p.body, p.date_posted, " .
           "p.date_updated, u.name as author, u.id as author_id, " .
           "u.signature as sig, c.count as postcount, " .
           "p.forum_id as forum_id, f.forum_moderator as mod, " .
           "p.update_id, u2.name as updated_by " .
         "FROM forum_forum f " .
         "JOIN forum_posts p " .
         "ON f.id = p.forum_id " .
         "JOIN forum_users u " .
         "ON u.id = p.author_id " .
         "LEFT JOIN forum_users u2 " .
         "ON u2.id = p.update_id " .
         "LEFT JOIN forum_postcount c " .
         "ON u.id = c.user_id " .
         "WHERE (p.topic_id = $topicid OR p.id = $topicid) " .
         "ORDER BY p.topic_id, p.date_posted ".
         "LIMIT $start,$limit";
  $result = mysql_query($sql,$conn)
    or die(mysql_error() . "<br>" . $sql);
  $pagelinks = paginate($limit);

With:
Code:
  $sql = "SELECT p.id, p.subject, p.body, p.date_posted, " .
           "p.date_updated, u.name as author, u.id as author_id, " .
           "u.signature as sig, c.count as postcount, " .
           "p.forum_id as forum_id, f.forum_moderator as mod, " .
           "p.update_id, u2.name as updated_by " .
         "FROM forum_forum f " .
         "LEFT JOIN forum_posts p " .
         "ON f.id = p.forum_id " .
         "LEFT JOIN forum_users u " .
         "ON u.id = p.author_id " .
         "LEFT JOIN forum_users u2 " .
         "ON u2.id = p.update_id " .
         "LEFT JOIN forum_postcount c " .
         "ON u.id = c.user_id " .
         "WHERE (p.topic_id = $topicid OR p.id = $topicid) " .
         "ORDER BY p.topic_id, p.date_posted ".
         "LIMIT $start,$limit";
  $result = mysql_query($sql,$conn)
    or die(mysql_error() . "<br>" . $sql);
  $query_count = "SELECT p.id, p.subject, p.body, p.date_posted, " .
           "p.date_updated, u.name as author, u.id as author_id, " .
           "u.signature as sig, c.count as postcount, " .
           "p.forum_id as forum_id, f.forum_moderator as mod, " .
           "p.update_id, u2.name as updated_by " .
         "FROM forum_forum f " .
         "LEFT JOIN forum_posts p " .
         "ON f.id = p.forum_id " .
         "LEFT JOIN forum_users u " .
         "ON u.id = p.author_id " .
         "LEFT JOIN forum_users u2 " .
         "ON u2.id = p.update_id " .
         "LEFT JOIN forum_postcount c " .
         "ON u.id = c.user_id " .
         "WHERE (p.topic_id = $topicid OR p.id = $topicid) " .
         "ORDER BY p.topic_id, p.date_posted ";
    $result_count = mysql_query($query_count);
    $totalrows = mysql_num_rows($result_count)
    or die(mysql_error() . "<br>" . $query_count);
  $pagelinks = paginate($limit,$totalrows);


Then in function paginate() further down

Replace:
Code:
  function paginate($limit=10) {
  global $admin;


  $sql = "SELECT FOUND_ROWS();";
  $result = mysql_query($sql) or die(mysql_error());
  $row = mysql_fetch_array($result);
  $numrows = $row[0];

With:
Code:
function paginate($limit=10,$totalrows) {
  global $admin;

  $numrows = $totalrows;


Now in viewforums.php

Replace:
Code:
  $sql = "SELECT SQL_CALC_FOUND_ROWS ".
           "t.id as topic_id, t.subject as t_subject, ".
           "u.name as t_author, count(p.id) as numreplies, ".
           "t.date_posted as t_posted, tmp.postdate as re_posted ".
         "FROM forum_users u ".
         "JOIN forum_posts t ".
         "ON t.author_id = u.id ".
         "LEFT JOIN tmp ".
         "ON t.id = tmp.topic_id ".
         "LEFT JOIN forum_posts p ".
         "ON p.topic_id = t.id ".
         "WHERE t.forum_id = $forumid ".
         "AND t.topic_id = 0 ".
         "GROUP BY t.id ".
         "ORDER BY re_posted DESC " .
         "LIMIT $start, $limit";
  $result = mysql_query($sql)
    or die(mysql_error()."<br>".$sql);
    $numrows = mysql_num_rows($result);

With:
Code:
  $sql = "SELECT t.id as topic_id, t.subject as t_subject, ".
           "u.name as t_author, count(p.id) as numreplies, ".
           "t.date_posted as t_posted, tmp.postdate as re_posted ".
         "FROM forum_users u ".
         "LEFT JOIN forum_posts t ".
         "ON t.author_id = u.id ".
         "LEFT JOIN tmp ".
         "ON t.id = tmp.topic_id ".
         "LEFT JOIN forum_posts p ".
         "ON p.topic_id = t.id ".
         "WHERE t.forum_id = $forumid ".
         "AND t.topic_id = 0 ".
         "GROUP BY t.id ".
         "ORDER BY re_posted DESC " .
         "LIMIT $start, $limit";
  $result = mysql_query($sql)
    or die(mysql_error()."<br>".$sql);
  $query_count = "SELECT t.id as topic_id, t.subject as t_subject, ".
           "u.name as t_author, count(p.id) as numreplies, ".
           "t.date_posted as t_posted, tmp.postdate as re_posted ".
         "FROM forum_users u ".
         "LEFT JOIN forum_posts t ".
         "ON t.author_id = u.id ".
         "LEFT JOIN tmp ".
         "ON t.id = tmp.topic_id ".
         "LEFT JOIN forum_posts p ".
         "ON p.topic_id = t.id ".
         "WHERE t.forum_id = $forumid ".
         "AND t.topic_id = 0 ".
         "GROUP BY t.id ".
         "ORDER BY re_posted DESC ";
    $result_count = mysql_query($query_count); 
    $numrows = mysql_num_rows($result_count);

Then 4 lines from the bottom:

Replace:
Code:
 echo paginate($limit);
With:
Code:
echo paginate($limit,$numrows);
I think that was all of it!

 
Old January 16th, 2005, 07:39 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the fix.

Your book is great - I've learned so much in a very short time.

 
Old March 10th, 2008, 02:46 PM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I'm trying to apply paginate() a database but when I click on any of the pagination links it returns me to my original form without any data.

Please help. Thank you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 15 problem golfbird BOOK: Beginning Visual C++ 6 7 September 9th, 2008 12:29 PM
chapter 15 checkout3.php problem derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 November 12th, 2006 10:11 AM
Chapter 15 Problem rsearing BOOK: Beginning ASP.NET 2.0 and Databases 3 October 12th, 2006 02:59 PM
Chapter 15 Search Problem PhilM BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 November 2nd, 2004 05:08 PM
A new chapter 15 problem with BBcodes PhilM BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 September 11th, 2004 11:11 PM





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