Link to home
Start Free TrialLog in
Avatar of Member_2_6479049
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\Intranet2014\aplicaciones\citas\calendar0115.php 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></TD> <?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></TD> <?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></TD> <?php
                        }else{
                              ?> <TD height="30" ALIGN=center bgcolor="#990000"><a href="horarios.php">3</a></TD> <?php
                        }
                        ?> </TR>
                        <TR> <?php
      ?> </TR>
      </TABLE>
      <?php
      }
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I don't know what is causing your main problem but this is wrong.  It is assigning a value instead of making a comparison.  A comparison is done with '==' and assignment is '='.
 // current
if($NOHABILES[2] = '00:00:00')
// should be
 if($NOHABILES[2] == '00:00:00')

Open in new window

$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].
Avatar of Member_2_6479049
Member_2_6479049

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\Intranet2014\aplicaciones\citas\calendar0115.php on line 116
my array contains this:
$result = mysqli_query($mysqli,"SELECT clave, anotramite,mestramite,diatramite,horatramite,COUNT(*) 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?
ASKER CERTIFIED SOLUTION
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great help !!!

Thank you.
Thanks for the points.