Solved

PHP - Warning: Cannot use a scalar value as an array in .....

Posted on 2015-01-28
6
53 Views
Last Modified: 2015-02-02
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
      }
0
Comment
Question by:elm9999
  • 3
  • 2
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40576254
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

0
 
LVL 9

Expert Comment

by:Brian Tao
ID: 40576300
$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].
0
 

Author Comment

by:elm9999
ID: 40576372
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?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Accepted Solution

by:
Brian Tao earned 500 total points
ID: 40576986
Should be something like this:
switch ($x) {
                     case 1:
                        if($NOHABILES[$d][2] == '00:00:00') {
// and the rest of your code

Open in new window

0
 

Author Closing Comment

by:elm9999
ID: 40584886
Great help !!!

Thank you.
0
 
LVL 9

Expert Comment

by:Brian Tao
ID: 40585032
Thanks for the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now