Arrays and Variables

A

Anonymous

Guest
Hey guys,

I just don't fuckin know what else to do here. Trying to run thru an array while grabbing some data out of a mysql database and just writing that data to a variable, which is made out of the name of the weekday that comes out of the array and some other standard text...

Here is the code:
Code:
$weekdays_eng = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$weekdays_var = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday");

for($a=0; $a<6; $a++) {

$query = "SELECT * FROM salary WHERE DAYNAME(card_date)='$weekdays_eng[$a]' AND callagent_id!='0' AND cancelation='0' AND card_time<='14:00:00'";
$result = mysql_query($query);
$lines = mysql_num_rows($result);
if($lines != "0") {
	for($i=1;$i<=$lines;$i++) {
		while($dataset = mysql_fetch_array($result)) {
			$weekdays_var[$a]._cards_beforenoon_sold = $dataset['card'] + $weekdays_var[$a]._cards_beforenoon_sold;
		}
	}
}
else {
	$weekdays_var[$a]._cards_beforenoon_sold = "0";
}

}

The error that I am getting is the following:
Parse error: parse error, unexpected '=', expecting ',' or ';' in statistics.php on line 10

Corrected the line number so it will fit this code, maybe somebody can help me out, I'd be really thankful.


-Eddie
 
First of all, this is a much cleaner solution:

Code:
$weekdays_eng = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$weekdays_var = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday");

for($a=0; $a<6; $a++) {

$query = "SELECT * FROM salary WHERE DAYNAME(card_date)='$weekdays_eng[$a]' AND callagent_id!='0' AND cancelation='0' AND card_time<='14:00:00'";
$result = mysql_query($query);

$weekdays_var[$a]._cards_beforenoon_sold = "0";

while($dataset = mysql_fetch_array($result)) {
   $weekdays_var[$a]._cards_beforenoon_sold = $dataset['card'] + $weekdays_var[$a]._cards_beforenoon_sold;
}

}

second of all, I take it by using $weekdays_var[$a]._cards_beforenoon_sold you are trying to reference _cards_beforenoon_sold as a member variable of class $weekdays_var[$a]. The problem is the . operator in PHP is for string appending, not member access. You'd use -> to get at _cards_before_noon_sold. Thirdly, I don't think you can do that anyway since $weekdays_var[$a] is of type string and is not a class. Thus it has no member variables.
 
What can I do now to solve the problem? I want to do the query in the database and find all entries that have been made on a special day (monday, tuesday, etc.) ... I am pretty new to all this but I need some kind of solution.

Maybe somebody can post me some code so I can find a way how to solve it, that would be awesome.


-Eddie
 
Code:
$weekdays_eng = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); 
$weekdays_var = array(
"Monday" => 0,
"Tuesday"=> 0,
"Wednesday" => 0,
"Thursday" => 0,
"Friday" => 0,
"Saturday" => 0); 

for($a=0; $a<6; $a++) { 

$query = "SELECT COUNT(*) AS 'count' FROM salary WHERE DAYNAME(card_date)='$weekdays_eng[$a]' AND callagent_id!='0' AND cancelation='0' AND card_time<='14:00:00'"; 

$result = mysql_query($query); 
$weekdays_var[$weekdays_eng[$a]] = $dataset['count']; 

}
 
Back
Top