View previous topic :: View next topic |
Author |
Message |
ayong -
Joined: 10 May 2008 Posts: 2 Location: KL, MY.
|
Posted: Sat May 10, 2008 10:33 pm Post subject: Syntax mysql error in php? |
|
|
Hello guys.
I'm php/mysql newbie. First time post this forum.
Ok, I got the following error message:
Quote: |
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 '; SELECT rank, full_name
|
An error only appears when I run the following mySQL statement on php:
mySQL:
Code: |
SET @rank:=0;
SELECT rank, full_name
FROM (SELECT @rank:=@rank+1 AS rank, full_name
FROM kelas ORDER BY jum DESC) AS foo
|
And, my php code:
Code: |
$sql = 'SET @rank:=0;'
. ' SELECT rank, full_name'
. ' FROM (SELECT @rank:=@rank+1 AS rank, full_name'
. ' FROM kelas ORDER BY jum DESC) AS foo LIMIT 0, 30';
|
Anything wrong with my php code? Or, it's about server...?
Thanks in advance. |
|
Back to top |
|
|
chewzzqq -
Joined: 28 Sep 2005 Posts: 198
|
Posted: Sun May 11, 2008 7:46 pm Post subject: |
|
|
The sql code's problem
Please google to find the right syntax near SELECT rank to use inside your MySQL version.
I can't help you,because surfing with windows mobile,slow........ _________________
|
|
Back to top |
|
|
DonQuichote -
Joined: 24 Dec 2006 Posts: 68 Location: The Netherlands
|
Posted: Sun May 11, 2008 9:15 pm Post subject: |
|
|
I assume you use some mysql_.. function. Through these functions, you can only send one query at a time. So you cannot combine the SET query with the SELECT query. |
|
Back to top |
|
|
ayong -
Joined: 10 May 2008 Posts: 2 Location: KL, MY.
|
Posted: Mon May 12, 2008 3:36 pm Post subject: |
|
|
chewzzqq wrote: | The sql code's problem
Please google to find the right syntax near SELECT rank to use inside your MySQL version.
I can't help you,because surfing with windows mobile,slow........ |
Very strange, the syntax work fine inside my mysql with following message:
Code: |
SET @rank :=0;# MySQL returned an empty result set (i.e. zero rows).
SELECT rank, full_name
FROM (
SELECT @rank := @rank +1 AS rank, user_id, full_name
FROM kelas
ORDER BY jum DESC
) AS foo
|
# MySQL returned an empty result set (i.e. zero rows) - what is it?
And, the mysql result are:
Code: |
Rank | Full Name
1 Mathew
2 Ronald
3 Sarah
. ..
. ..
|
DonQuichote wrote: | I assume you use some mysql_.. function. Through these functions, you can only send one query at a time. So you cannot combine the SET query with the SELECT query. |
So far, i don't use some function, just a simple php. Here is the code for php:
Code: | <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'exam';
$link = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect to the DB server');
mysql_select_db($db, $link) or die('Could not select the DB');
$sql = 'SET @rank:=0;'
. ' SELECT rank, user_id, full_name'
.' FROM (SELECT @rank:=@rank+1 AS rank, user_id, full_name'
.' FROM kelas ORDER BY jum DESC) AS foo LIMIT 0, 30;';
mysql_query($sql);
$result = mysql_query($sql) or die($sql.' '.mysql_error());
:
result
:
?>
|
Thanks anyway. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|