Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 March 7th, 2006, 01:05 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 16 forum - SQL error

Hi

I've got a copy of Beginning PHP5, Apache, and MySQL Web Development.

I've been working through Chapter 16 and get this error when loading the index page:

--------begin cut---------
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod FROM forum_forum f LEFT JOIN forum_posts p ON f.id = p.forum_id AND ' at line 3
-------end cut--------

Here is the offending bit of code:


-------Begin cut--------
$sql = <<<EOS
  SELECT f.id as id, f.forum_name as forum,
    f.forum_desc as description,
    count(forum_id) as threads, u.name as mod
  FROM forum_forum f
  LEFT JOIN forum_posts p
  ON f.id = p.forum_id
  AND p.topic_id=0
  LEFT JOIN forum_users u
  ON f.forum_moderator = u.id
  GROUP BY f.id,
EOS;
--------end cut----------

Somone on another forum suggested I added "f.forum_name, f.forum_desc, u.name" on the end of the group by statement. I've tried this and it doesn't work.

Can anyone help????

Cheers
Pete Fernando


 
Old March 13th, 2006, 02:49 PM
Authorized User
 
Join Date: Mar 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

chnage u.name as mod to u.name as `mod`. The word mod is a MySQL reserved word and so MySQL gets confused. When you place blackticks or quotes around it, it tells MySQL you are not using a MySQL reserved word

 
Old March 31st, 2006, 01:23 AM
Authorized User
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Don't Use mod Because it's a mysql built in function,
another thing, U r using aggregate function count
therefore other colum should be in group by clause
your group by should look like this and should use id in place of f.id
and so on.
GROUP BY id,forum,description






Similar Threads
Thread Thread Starter Forum Replies Last Post
Forum Chapter 16 - changing the dates mr_badger BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 31st, 2008 07:50 PM
Search Error Chapter 16 EgoGen BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 12th, 2008 03:36 PM
Chapter 16 Sql connection error flashmanTom BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 May 22nd, 2008 05:04 PM
Chapter 16 forum - SQL error petefernando PHP Databases 3 October 22nd, 2007 07:13 PM





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