Subject: Chapter 3 Exercise 3
Posted By: Matt WAXON Post Date: 4/18/2005 6:53:11 AM
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 By: dbdave Reply Date: 5/15/2005 11:31:44 AM
Can you post back the entire code you've tried to use?

Reply By: club662 Reply Date: 6/28/2005 12:28:45 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

$offset = $_REQUEST['offset']


you have to do this


//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 By: club662 Reply Date: 7/4/2005 2:19:13 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;


Go to topic 32393

Return to index page 517
Return to index page 516
Return to index page 515
Return to index page 514
Return to index page 513
Return to index page 512
Return to index page 511
Return to index page 510
Return to index page 509
Return to index page 508