View Single Post
  #2 (permalink)  
Old February 3rd, 2004, 02:48 PM
nikolai nikolai is offline
Friend of Wrox
Points: 1,708, Level: 16
Points: 1,708, Level: 16 Points: 1,708, Level: 16 Points: 1,708, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA.
Posts: 833
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know if this is causing a problem, but you end up throwing away one of your result rows.

You call mysql_fetch_array($viewall) before your if() statement, then you call it in the conditional expression of your while() loop again, without ever using the first result row.

There's a lot of code there, and it's pretty messy, so it's difficult for someone to just read through it looking for problems. If you're still having problems, I STRONGLY suggest you beautify your code -- use proper indentation and spacing.

For example, this is your code:

Code:
<?php
$bil=1;
while($senarai=mysql_fetch_array($viewall))
{
$viewCheck=query("SELECT id FROM tempfailure WHERE id = DATE_FORMAT('{$senarai["waktuTamat"]}','%m') ORDER BY id", $link, __LINE__, __FILE__);
$periksa=mysql_fetch_array($viewCheck);

if (date("m",$senarai["waktuTamat"])==$periksa["id"])
{
$nilai=$periksa["jumlah"]+1;
$SQLupd=query("UPDATE tempfailure SET jumlah = '$nilai' WHERE id =DATE_FORMAT('{$senarai["waktuTamat"]}','%m')", $link, __LINE__, __FILE__);
}
$bil=$bil+1;
}
echo date("m",$senarai["waktuTamat"]);
?>
And this is it again with more sensible formatting:
Code:
<?php

$bil = 1;

while ($senarai = mysql_fetch_array($viewall))
{
    $waktuTamat = &$senerai['waktuTamat'];

    $query = "SELECT id FROM tempfailure 
               WHERE id = DATE_FORMAT('{$waktuTamat}', '%m')
               ORDER BY id";

    $viewCheck = query($query, $link, __LINE__, __FILE__);

    $periksa = mysql_fetch_array($viewCheck);

    if (date("m", $waktuTamat) == $periksa["id"])
    {
        $nilai = $periksa["jumlah"] + 1;
        $query = "UPDATE tempfailure
                     SET jumlah = '$nilai'
                   WHERE id     = DATE_FORMAT('{$waktuTamat}','%m')"

        $SQLupd = query($query, $link, __LINE__, __FILE__);
    }

    $bil = $bil + 1;
}

echo date("m", $senarai["waktuTamat"]);
?>
In my opinion, the second version is MUCH easier to read.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote