Page 1 of 1

strings ...

Posted: Wed Dec 10, 2003 12:52 am
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??

Posted: Wed Dec 10, 2003 2:37 am
by Weirdan
Is this line in a class definition? If not you can't use var then.

Posted: Wed Dec 10, 2003 3:13 am
by baz113
yes, it is in a class definition.

Posted: Wed Dec 10, 2003 3:32 am
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

Posted: Wed Dec 10, 2003 3:55 am
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.

Posted: Wed Dec 10, 2003 4:10 am
by Weirdan
could you post a little more code of your class?

Posted: Wed Dec 10, 2003 4:17 am
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

Posted: Wed Dec 10, 2003 12:10 pm
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__);
}
}

}

Posted: Wed Dec 10, 2003 1:21 pm
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]

Posted: Wed Dec 10, 2003 2:46 pm
by m3mn0n