Member_2_6479049
asked on
PHP - Warning: Cannot use a scalar value as an array in .....
Hello guys,
Well, this is the first time working with arrays, what I need is to check if my array $NOHABILES in column 2 has this value "00:00:00", so I can display what I need but I'm doing something wrong.
This is the error
Warning: Cannot use a scalar value as an array in C:\inetpub\wwwroot\Intrane t2014\apli caciones\c itas\calen dar0115.ph p on line 218
<?php
foreach ($NOHABILES as $d => $x){
switch ($x[1]) {
case 1:
if($NOHABILES[2] = '00:00:00') {
?> <TD height="30" ALIGN=center bgcolor="#666666">1</a></T D> <?php
}else{
?> <TD height="30" ALIGN=center bgcolor="#990000"><a href="horarios.php">1</a>< /TD> <?php
}
case 2:
if($NOHABILES[2] = '00:00:00') {
?> <TD height="30" ALIGN=center bgcolor="#666666">2</a></T D> <?php
}else{
?> <TD height="30" ALIGN=center bgcolor="#990000"><a href="horarios.php">2</a>< /TD> <?php
}
case 3:
if($NOHABILES[2] = '00:00:00') {
?> <TD height="30" ALIGN=center bgcolor="#666666">3</a></T D> <?php
}else{
?> <TD height="30" ALIGN=center bgcolor="#990000"><a href="horarios.php">3</a>< /TD> <?php
}
?> </TR>
<TR> <?php
?> </TR>
</TABLE>
<?php
}
Well, this is the first time working with arrays, what I need is to check if my array $NOHABILES in column 2 has this value "00:00:00", so I can display what I need but I'm doing something wrong.
This is the error
Warning: Cannot use a scalar value as an array in C:\inetpub\wwwroot\Intrane
<?php
foreach ($NOHABILES as $d => $x){
switch ($x[1]) {
case 1:
if($NOHABILES[2] = '00:00:00') {
?> <TD height="30" ALIGN=center bgcolor="#666666">1</a></T
}else{
?> <TD height="30" ALIGN=center bgcolor="#990000"><a href="horarios.php">1</a><
}
case 2:
if($NOHABILES[2] = '00:00:00') {
?> <TD height="30" ALIGN=center bgcolor="#666666">2</a></T
}else{
?> <TD height="30" ALIGN=center bgcolor="#990000"><a href="horarios.php">2</a><
}
case 3:
if($NOHABILES[2] = '00:00:00') {
?> <TD height="30" ALIGN=center bgcolor="#666666">3</a></T
}else{
?> <TD height="30" ALIGN=center bgcolor="#990000"><a href="horarios.php">3</a><
}
?> </TR>
<TR> <?php
?> </TR>
</TABLE>
<?php
}
$x is an element of the array $NOHABILES, but in the switch statement, you're trying to use it as an array by $x[1].
ASKER
Thank you Dave & Taoyipai :)
I already change to if($NOHABILES[2] == '00:00:00') but now the error is this:
Notice: Undefined offset: 2 in C:\inetpub\wwwroot\Intrane t2014\apli caciones\c itas\calen dar0115.ph p on line 116
my array contains this:
$result = mysqli_query($mysqli,"SELE CT clave, anotramite,mestramite,diat ramite,hor atramite,C OUNT(*) FROM transacciones WHERE anotramite = '$ano' && mestramite = '$mes' GROUP BY diatramite,horatramite ORDER BY anotramite, mestramite, diatramite, horatramite");
if ($result) {
while($row = mysqli_fetch_array($result )) {
$NOHABILES[$row[0]][1] = $row["diatramite"];
$NOHABILES[$row[0]][2] = $row["horatramite"];
$NOHABILES[$row[0]][3] = $row["COUNT(*)"];
$totalxdia = ($row["COUNT(*)"] += "$totalxdia");
}
mysqli_close($mysqli);
}
So, how to make the switch statement?
I already change to if($NOHABILES[2] == '00:00:00') but now the error is this:
Notice: Undefined offset: 2 in C:\inetpub\wwwroot\Intrane
my array contains this:
$result = mysqli_query($mysqli,"SELE
if ($result) {
while($row = mysqli_fetch_array($result
$NOHABILES[$row[0]][1] = $row["diatramite"];
$NOHABILES[$row[0]][2] = $row["horatramite"];
$NOHABILES[$row[0]][3] = $row["COUNT(*)"];
$totalxdia = ($row["COUNT(*)"] += "$totalxdia");
}
mysqli_close($mysqli);
}
So, how to make the switch statement?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great help !!!
Thank you.
Thank you.
Thanks for the points.
Open in new window