p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 (http://p2p.wrox.com/forumdisplay.php?f=123)
-   -   Chapter 3 Exercise 3 (http://p2p.wrox.com/showthread.php?t=28246)

Matt WAXON April 18th, 2005 06:53 AM

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?


dbdave May 15th, 2005 11:31 AM

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


club662 June 28th, 2005 12:28 PM

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;


club662 July 4th, 2005 02:19 AM

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;


All times are GMT -4. The time now is 10:54 AM.

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