Wrox Programmer Forums
|
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 April 18th, 2005, 06:53 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3 Exercise 3

I am stuck with the do it yourself exercise for Chapter 3... I've checked the answer and everything looks the same, but I keep getting this error message:

'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 '1' at line 4':o

referring to:

'LIMIT $offset,1";'

Any ideas how I make it work?

 
Old May 15th, 2005, 11:31 AM
Authorized User
 
Join Date: May 2005
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you post back the entire code you've tried to use?

 
Old June 28th, 2005, 12:28 PM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i had the same problem,
the problem is that the $offset variable does not get initialised until you define it in the url (localhost/page.php?offset=n).

When you just go to localhost/page.php
the mysql query will look like this:
"SELECT movie_name, movie_year " .
"FROM movie " .
"ORDER BY movie_name " .
"LIMIT ,1"

whilst mysql expects a "LIMIT n,x"

So you have to set a value for offset ONLY when it has no value yet.
As this is not yet explained at that point, this is the answer:


Instead of
Code:
$offset = $_REQUEST['offset']
you have to do this

Code:
//make sure a value is assigned to $offset if it not yet exists.
if ($_REQUEST['offset'] == NULL
 {
  $offset=0;
 } 
else
 {
 $offset=$_REQUEST['offset'];
 }
//just to double check
echo $offset;
 
Old July 4th, 2005, 02:19 AM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For those not comfortable using this particular syntax (i am not sure if it has limitations compared to the next example) here is another way to do it:

if (!isset($_REQUEST['offset'])
{
$offset=0;
}
else
{
 $offset=$_REQUEST['offset'];
}

echo $offset;





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Exercise 2 diango BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 February 1st, 2011 03:24 PM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Chapter 5 - Exercise 1 scgtman BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 16th, 2006 08:10 PM
Chapter 4, Exercise 3 DRAYKKO BOOK: Beginning Java 2 3 July 9th, 2004 02:34 PM
Chapter 8, Exercise 4 cjo BOOK: Beginning ASP.NET 1.0 0 November 3rd, 2003 02:26 PM





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