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?

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';
    }
}

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.

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'];
 
        
    }

Absolutely:

<?php
$day[] = $data['od_week'];

$day will be a numerically indexed array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.