strings ...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
baz113
Forum Newbie
Posts: 4
Joined: Thu Nov 20, 2003 11:05 am

strings ...

Post by baz113 »

I have this piece of code:

var $query2 = "SELECT studentid, _uid FROM lw_students WHERE groupid = $this->groupid"; //line 46

and I get this error:
Parse error: parse error in ... .php on line 46

I was under the impression that double quotes is usable for strings, and moreover, required if you want to include a variable name within the quotes.

Whats wrong??
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Is this line in a class definition? If not you can't use var then.
baz113
Forum Newbie
Posts: 4
Joined: Thu Nov 20, 2003 11:05 am

Post by baz113 »

yes, it is in a class definition.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Try heredoc 8) :lol::

Code: Select all

var $query2 = <<< SQL
SELECT studentid, _uid FROM lw_students WHERE groupid = $this->groupid
SQL;
Or maybe also:

Code: Select all

var $query2 = "SELECT studentid, _uid FROM lw_students WHERE groupid = '" . $this->groupid; . "'";
-Nay
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

Not Sure....
but wudn't this work like this ??

Code: Select all

<?php
var $query2 = "SELECT studentid, _uid FROM lw_students WHERE groupid = '$this->groupid'";

?>
the second option Nay gave looks like best way to me, but just a thought.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

could you post a little more code of your class?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

igoy wrote:Not Sure....
but wudn't this work like this ??

Code: Select all

<?php
var $query2 = "SELECT studentid, _uid FROM lw_students WHERE groupid = '$this->groupid'";

?>
the second option Nay gave looks like best way to me, but just a thought.
Ahh, the Nay is in bold 8) :D.

-Nay
baz113
Forum Newbie
Posts: 4
Joined: Thu Nov 20, 2003 11:05 am

Post by baz113 »

here is the class definition. i've been playing around with the string contatenation but still recieve parse errors ...
-----

class cronTimesheetEmail{

var $ownEntryArray = array();
var $groupStudents = array();
var $groupid;
var $userID;
var $studentID;
var $ownEntry;
var $approvalEntryID;
var $studentApprovalEntryID;
var $entryTime;
var $emailAddress;
var $message = "There are Timesheets that have been pending your review for more than 3 days. Please take care of this soon.";
var $subject = "LUDWING Timesheets awaiting your review";
var $query1 = "SELECT groupid FROM lw_groups";
var $query2 = "SELECT studentid, _uid FROM lw_students WHERE groupid ='".$this->groupid."'";
var $query3 = "SELECT entryid, whensubmitted FROM lw_timesheets WHERE studentid ='".$this->studentID."'";
var $temp1 = 'SELECT lw_timesheetapprovals.entryid, lw_timesheetapprovals.studentid, TO_DAYS(lw_timesheets.whensubmitted) As submitted';
var $temp2 = 'FROM lw_timesheetapprovals, lw_timesheets';
var $temp3 = 'WHERE lw_timesheetapprovals.entryid = lw_timesheets.entryid ';
var $quer4 = $temp1." ".$temp2." ".$temp3;
var $query5 = "SELECT email FROM lw_users WHERE _uid ='".$this->userID."'";

function queryErrorCheck( $result )
{
if (!$result)
{
$msg = 'MySQL error #' . mysql_errno() . ": " . mysql_error();
reportError($msg, __FILE__, __LINE__);
}
}

}
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Ahhh... you have non-constant initializer. You can't do it in PHP4.
use constructor instead:

Code: Select all

//...skipped....
var $query5;
//....skipped....
function cronTimesheetEmail(){ //constructor
//....skipped....
$this->query5 = "SELECT email FROM lw_users WHERE _uid ='".$this->userID."'"; 
//...skipped....
[edit]
Forgot to add `$this->` before the `$query5`. Just used to use C++ :oops:
[/edit]
Last edited by Weirdan on Wed Dec 10, 2003 3:11 pm, edited 1 time in total.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Post Reply