PDA

View Full Version : code problem


DeadGaze
08-10-2004, 09:51 PM
HElp
i created the following code
but i dosnt get what i want can someone make it for me good

thanxss

$time1_today=date("D d-m-y");
$daytoday1=$DB_site->query("SELECT time FROM other");
if ($daytoday1 == $time1_today) {
$DB_site->query("UPDATE other SET time='$time1_today'");
$DB_site->query("UPDATE user SET level=level-1");
} else {
}

filburt1
08-10-2004, 09:56 PM
HElp
i created the following code
but i dosnt get what i want can someone make it for me good

thanxss

$time1_today=date("D d-m-y");
$daytoday1=$DB_site->query("SELECT time FROM other");
if ($daytoday1 == $time1_today) {
$DB_site->query("UPDATE other SET time='$time1_today'");
$DB_site->query("UPDATE user SET level=level-1");
} else {
}

1. You need to describe what your code is supposed to be doing.
2. Please surround your code with tags instead of [code] tags to enable color formatting.
3. The else block is redundant and can be deleted.
4. I strongly recommend that you get in the habit of indenting your code. For example:
[php]
$time1_today = date("D d-m-y");
$daytoday1 = $DB_site->query("SELECT time FROM other");
if ($daytoday1 == $time1_today)
{
$DB_site->query("UPDATE other SET time='$time1_today'");
$DB_site->query("UPDATE user SET level=level-1");
}

5. The $daytoday1 variable is not set to what you expect. The proper replacement:

$result = $DB_site->query_first("SELECT time FROM other"); // shouldn't there be a WHERE clause?
$daytoday1 = $result['time'];

DeadGaze
08-11-2004, 09:21 AM
ow iam sorry hehe
well the code is working now
but the wrong way hehe
i wanted to have a code when switching from day he do it but now he stay entering the code
till it is the next day
only wanted to do the code when the switch is going to the next day

$result = $DB_site->query_first("SELECT * FROM other WHERE time"); // shouldn't there be a WHERE clause?
$daytoday1 = $result['time'];
$time1_today=date("D d-m-y");
//$daytoday1=$DB_site->query("SELECT * FROM other WHERE time");
if ($daytoday1 == $time1_today) {
$DB_site->query("UPDATE other SET test='$time1_today'");

} else {
$DB_site->query("UPDATE other SET time='$time1_today'");
$DB_site->query("UPDATE user SET level=level-1");
}


Thanxs