0

Hi all,
how do i compare one date with a list of array which consist of date?

$date = 1990-12-3

$viewSchedule = "select * from schedule where id_user = '$idHairstlylist'";
$scheduleResult = mysqli_query($dbConn,$viewSchedule) or die(mysqli_error($dbConn));

while ($row1 = mysqli_fetch_array($scheduleResult)){
            for($j=1;$j<=4;$j++){
		$day[$j] = $row1['od_week'.$j];
                
             if ($day[$j]!= $date){
               echo 'hi';
                }
            }

issit possible?

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by mschroeder
0

Yep, pretty much anything's possible in today's programming world. You just have to concentrate.

First off, since PHP would try to subtract that $date variable, we need to make it a string so make it this:

$date = '1990-12-3';

It also seems you've mispelled a function in your code (mysqli_query should be mysql_query). Maybe that could be the problem?

Also, you don't need to put $j inside the array of the row - it should work just fine, depending on how your $day array is set up.

$date = '1990-12-3';

$viewSchedule = "select * from schedule where id_user = '$idHairstlylist'";
$scheduleResult = mysql_query($dbConn,$viewSchedule) or die(mysqli_error($dbConn));

while ($data = mysql_fetch_array($scheduleResult))
{
    for ($j = 0; $j <= 4; $j++)
    {
        $day[$j] = $data['od_week'];

        // Only one line of processing after the statement... no need for brackets
        if ($day[$j] != $date)
           echo 'hi';
    }
}

Edited by sutt0n: n/a

0

Yep, pretty much anything's possible in today's programming world. You just have to concentrate.

First off, since PHP would try to subtract that $date variable, we need to make it a string so make it this:

$date = '1990-12-3';

It also seems you've mispelled a function in your code (mysqli_query should be mysql_query). Maybe that could be the problem?

Also, you don't need to put $j inside the array of the row - it should work just fine, depending on how your $day array is set up.

$date = '1990-12-3';

$viewSchedule = "select * from schedule where id_user = '$idHairstlylist'";
$scheduleResult = mysql_query($dbConn,$viewSchedule) or die(mysqli_error($dbConn));

while ($data = mysql_fetch_array($scheduleResult))
{
    for ($j = 0; $j <= 4; $j++)
    {
        $day[$j] = $data['od_week'];

        // Only one line of processing after the statement... no need for brackets
        if ($day[$j] != $date)
           echo 'hi';
    }
}

sutt0n is correct about your date needing to be in a string.

However, you should NEVER use the mysql* family of functions unless you're using a very old version of MySQL. The mysqli* functions as you used in your code, are designed to work with the "new" functionality that exists in MySQL since version 4.1.

Also, while not wrong it is a pet peeve, you should always code to a standard. Eliminating those braces is just lazy programming IMO. You lose the ability to tell where the control structure begins or ends and if you were to add additional code after echo 'hi'; you will have issues if you don't realize you're missing braces. Just constructive criticism.

Edited by mschroeder: n/a

0

Alright, i'll take note of it. Thanks.

I've another question. Is it possible to store values into array whereby i dont use any for loop?

while ($data = mysql_fetch_array($scheduleResult))
{
    
        $day[$j] = $data['od_week'];
 
        
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.