Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 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 Search this Thread Display Modes
  #1 (permalink)  
Old April 18th, 2005, 06:53 AM
Registered User
 
Join Date: Apr 2005
Location: , , .
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?

Reply With Quote
  #2 (permalink)  
Old May 15th, 2005, 11:31 AM
Authorized User
 
Join Date: May 2005
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #3 (permalink)  
Old June 28th, 2005, 12:28 PM
Authorized User
 
Join Date: Jun 2005
Location: , , .
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;
Reply With Quote
  #4 (permalink)  
Old July 4th, 2005, 02:19 AM
Authorized User
 
Join Date: Jun 2005
Location: , , .
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;
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
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



All times are GMT -4. The time now is 04:00 PM.


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