Help needed on PHP Query generation
Help needed on PHP Query generation
am 20.07.2006 15:11:45 von totalstranger
Can someone please tell me why this PHP statement throws the following
PHP error:
Parse error: parse error, unexpected '=' in
/var/www/html/PHP/XXXXXXXX.php on line 335 (line 335 is the Where
portion of the script below)
$query = 'SELECT Venue.*, '
.. ' CONCAT_WS(\' \', Users2.Firstname, Users2.Lastname,
Date_Format(Venue.Vnu_Add_Date, \'%b %e, %Y %T\' )) as Mnt_Add, '
.. ' CONCAT_WS(\' \', Users.Firstname, Users.Lastname,
Date_Format(Venue.Lastmaint, \'%b %e, %Y %T\' )) as Mnt_Data '
.. ' FROM `Venue`'
.. ' LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id'
.. ' LEFT JOIN Users ON Venue.Maint_Userid = Users.Id'
.. ' WHERE Venue.Id = '.$Id_clean;
Similar code on other scripts works without a problem and I'm unable to
find this error.
Thank you
Re: Help needed on PHP Query generation
am 20.07.2006 15:33:02 von totalstranger
On or about 7/20/2006 9:11 AM, it came to pass that totalstranger wrote:
> Can someone please tell me why this PHP statement throws the following
> PHP error:
> Parse error: parse error, unexpected '=' in
> /var/www/html/PHP/XXXXXXXX.php on line 335 (line 335 is the Where
> portion of the script below)
>
> $query = 'SELECT Venue.*, '
> . ' CONCAT_WS(\' \', Users2.Firstname, Users2.Lastname,
> Date_Format(Venue.Vnu_Add_Date, \'%b %e, %Y %T\' )) as Mnt_Add, '
> . ' CONCAT_WS(\' \', Users.Firstname, Users.Lastname,
> Date_Format(Venue.Lastmaint, \'%b %e, %Y %T\' )) as Mnt_Data '
> . ' FROM `Venue`'
> . ' LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id'
> . ' LEFT JOIN Users ON Venue.Maint_Userid = Users.Id'
> . ' WHERE Venue.Id = '.$Id_clean;
>
>
> Similar code on other scripts works without a problem and I'm unable to
> find this error.
>
> Thank you
This version also fails with same error
$query = "SELECT Venue.*, "
.. " CONCAT_WS(' ', Users2.Firstname, Users2.Lastname,
Date_Format(Venue.Vnu_Add_Date, '%b %e, %Y %T' )) as Mnt_Add, "
.. " CONCAT_WS(' ', Users.Firstname, Users.Lastname,
Date_Format(Venue.Lastmaint, '%b %e, %Y %T' )) as Mnt_Data "
.. " FROM `Venue`"
.. " LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id"
.. " LEFT JOIN Users ON Venue.Maint_Userid = Users.Id"
.. " WHERE Venue.Id = ".$Id_clean;
Re: Help needed on PHP Query generation
am 20.07.2006 15:36:49 von Rik
totalstranger wrote:
> Can someone please tell me why this PHP statement throws the following
> PHP error:
> Parse error: parse error, unexpected '=' in
> /var/www/html/PHP/XXXXXXXX.php on line 335 (line 335 is the Where
> portion of the script below)
>
> $query = 'SELECT Venue.*, '
> . ' CONCAT_WS(\' \', Users2.Firstname, Users2.Lastname,
> Date_Format(Venue.Vnu_Add_Date, \'%b %e, %Y %T\' )) as Mnt_Add, '
> . ' CONCAT_WS(\' \', Users.Firstname, Users.Lastname,
> Date_Format(Venue.Lastmaint, \'%b %e, %Y %T\' )) as Mnt_Data '
> . ' FROM `Venue`'
> . ' LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id'
> . ' LEFT JOIN Users ON Venue.Maint_Userid = Users.Id'
> . ' WHERE Venue.Id = '.$Id_clean;
>
>
> Similar code on other scripts works without a problem and I'm unable
> to find this error.
I cannot seem te reproduce the error with the same script, so I wouldn't
know. Are you very sure this is the EXACT script? no accidental switching of
backticks and quotes?
You do know however, that linebreaks are perfectly legal, and you dont have
concatenate your whole query?
So:
SELECT Venue.*,
CONCAT_WS(\' \', Users2.Firstname, Users2.Lastname,
Date_Format(Venue.Vnu_Add_Date, \'%b %e, %Y %T\' )) as Mnt_Add,
CONCAT_WS(\' \', Users.Firstname, Users.Lastname,
Date_Format(Venue.Lastmaint, \'%b %e, %Y %T\' )) as Mnt_Data
FROM `Venue`
LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id
LEFT JOIN Users ON Venue.Maint_Userid = Users.Id
WHERE Venue.Id = '.$Id_clean;
...works perfectly and will make your life a little easier.
Grtz,
--
Rik Wasmus
Re: Help needed on PHP Query generation
am 20.07.2006 15:43:25 von totalstranger
On or about 7/20/2006 9:33 AM, it came to pass that totalstranger wrote:
> On or about 7/20/2006 9:11 AM, it came to pass that totalstranger wrote:
>> Can someone please tell me why this PHP statement throws the following
>> PHP error:
>> Parse error: parse error, unexpected '=' in
>> /var/www/html/PHP/XXXXXXXX.php on line 335 (line 335 is the Where
>> portion of the script below)
>>
>> $query = 'SELECT Venue.*, '
>> . ' CONCAT_WS(\' \', Users2.Firstname, Users2.Lastname,
>> Date_Format(Venue.Vnu_Add_Date, \'%b %e, %Y %T\' )) as Mnt_Add, '
>> . ' CONCAT_WS(\' \', Users.Firstname, Users.Lastname,
>> Date_Format(Venue.Lastmaint, \'%b %e, %Y %T\' )) as Mnt_Data '
>> . ' FROM `Venue`'
>> . ' LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id'
>> . ' LEFT JOIN Users ON Venue.Maint_Userid = Users.Id'
>> . ' WHERE Venue.Id = '.$Id_clean;
>>
>>
>> Similar code on other scripts works without a problem and I'm unable
>> to find this error.
>>
>> Thank you
>
> This version also fails with same error
> $query = "SELECT Venue.*, "
> . " CONCAT_WS(' ', Users2.Firstname, Users2.Lastname,
> Date_Format(Venue.Vnu_Add_Date, '%b %e, %Y %T' )) as Mnt_Add, "
> . " CONCAT_WS(' ', Users.Firstname, Users.Lastname,
> Date_Format(Venue.Lastmaint, '%b %e, %Y %T' )) as Mnt_Data "
> . " FROM `Venue`"
> . " LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id"
> . " LEFT JOIN Users ON Venue.Maint_Userid = Users.Id"
> . " WHERE Venue.Id = ".$Id_clean;
Aaaargh
This error was caused by my messing up the line following this statement
from
$result = mysql_query( $query )
to
result = mysql_query( $query )
Re: Help needed on PHP Query generation
am 20.07.2006 16:05:22 von totalstranger
On or about 7/20/2006 9:36 AM, it came to pass that Rik wrote:
> totalstranger wrote:
>> Can someone please tell me why this PHP statement throws the following
>> PHP error:
>> Parse error: parse error, unexpected '=' in
>> /var/www/html/PHP/XXXXXXXX.php on line 335 (line 335 is the Where
>> portion of the script below)
>>
>> $query = 'SELECT Venue.*, '
>> . ' CONCAT_WS(\' \', Users2.Firstname, Users2.Lastname,
>> Date_Format(Venue.Vnu_Add_Date, \'%b %e, %Y %T\' )) as Mnt_Add, '
>> . ' CONCAT_WS(\' \', Users.Firstname, Users.Lastname,
>> Date_Format(Venue.Lastmaint, \'%b %e, %Y %T\' )) as Mnt_Data '
>> . ' FROM `Venue`'
>> . ' LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id'
>> . ' LEFT JOIN Users ON Venue.Maint_Userid = Users.Id'
>> . ' WHERE Venue.Id = '.$Id_clean;
>>
>>
>> Similar code on other scripts works without a problem and I'm unable
>> to find this error.
>
> I cannot seem te reproduce the error with the same script, so I wouldn't
> know. Are you very sure this is the EXACT script? no accidental switching of
> backticks and quotes?
>
>
> You do know however, that linebreaks are perfectly legal, and you dont have
> concatenate your whole query?
> So:
> SELECT Venue.*,
> CONCAT_WS(\' \', Users2.Firstname, Users2.Lastname,
> Date_Format(Venue.Vnu_Add_Date, \'%b %e, %Y %T\' )) as Mnt_Add,
> CONCAT_WS(\' \', Users.Firstname, Users.Lastname,
> Date_Format(Venue.Lastmaint, \'%b %e, %Y %T\' )) as Mnt_Data
> FROM `Venue`
> LEFT JOIN Users as Users2 ON Venue.Vnu_Add_Userid = Users2.Id
> LEFT JOIN Users ON Venue.Maint_Userid = Users.Id
> WHERE Venue.Id = '.$Id_clean;
>
> ..works perfectly and will make your life a little easier.
>
> Grtz,
Thank you for taking a look, the error was caused by the next statement
missing a dollar sign (see my previous post)
Yeah U Right on the concatenation, just a personal coding habit. Will
give your advice a try.
Thank you