Re: Cannot use a scalar value as an array
| From: | Steve Cayford | Date: | Tue, 04 Dec 2001 15:50:22 +0000 |
| Subject: | Re: Cannot use a scalar value as an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-76534@lists.php.net to get a copy of this message | ||
On Tuesday, December 4, 2001, at 06:04 AM, Xavier Antoviaque wrote:
Hello all,
I have a problem with a php script, which I want to use to fetch two data
(integer) from a MySQL table, divide the first by the second, and store the
value resulting in an double array. That seems not very difficult, but I
always have the error 'Cannot use a scalar value as an array' when I use my
script.
Here it is :
$result = mysql_query("SELECT timestamp_c,connectes,num FROM
stats_serveurs WHERE timestamp_c LIKE '".$date."%' "AND serveur='".
$serveur."'", $link);
$max = 0;
$reps = mysql_num_rows($result);
for($i = 1; $i<=$reps; $i++){
$row = mysql_fetch_row($result);
$serveur[$i]['heure'] = $row[0];
$serveur[$i]['connectes'] = (int) ($row[1] / $row[2]); // Error!
$max = max($max, $serveur[$i]['connectes']);
}
How does the operator precedence work in the statement ($row[1] / $row[2]) ? You might try (($row[1]) / ($row[2])) instead, or pull those into scalar variables before trying the division.
-Steve
Any help is welcome ! :-) -- Xavier. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net