Page 1 of 1

Variables Not Changing Values To Next Row in DB

Posted: Sun Mar 02, 2003 4:59 pm
by justravis
I'm echoing rows from a db. It seems that some variables hold the values of the last record if they are NULL in the current record.

There are 2 variables in my code, $pdf & $dir, that seem to exhibit this problem.

I wrote the code, so that it would output a link to the pdf only if one actually existed. Instead, when a pdf does not exist, it outputs a link to the last row's pdf. The link contains the $dir from the last row as well, EVEN if the current row has a $dir of its own.

Any potential solutions would be greatly appeciated.

Code: Select all

$art_result=mysql_query("SELECT id, title, dir, pdf FROM article WHERE issid='$issid'");

while($articles=mysql_fetch_array($art_result))
{
        $artid=$articles[id];
        $title=$articles[title];
        $dir=$articles[dir];
        $pdf=$articles[pdf];

        echo "<b><font size=$art_font_size>$title</font><br>\n";

        if($show_authors)
        {
                author_list($artid);
        }

        $abstractlink="<a href=# onClick='abstractWindow($artid)'>[abstract]</a>";

        if(session_check())
        {
                $artlink="<a href='archive.php?selectyr=$yr&selectseason=$season&selectart=$artid'
 target='btm'>[view]</a>";

                if($pdf)
                {
                        $pdflink ="<a href='../journals/$yr/" . strtolower($season) . "/$dir/index
_files/$pdf' target=right>";
                        $pdflink .='[pdf]</a>';

                        #Failed attempt to reset var.
                        #$pdf=0;
                }
        }
        else
        {
                $artlink="<a href=# onClick='nologinWindow()'>[view]</a>";

                if($pdf)
                {
                        $pdflink="<a href=# onClick='nologinWindow()'>[pdf]</a>";

                        #Failed attempt to reset var.
                        #$pdf=0;
                }
        }

        echo "$abstractlink $artlink $pdflink<br>\n";

        if($artcle_num==mysql_num_rows($art_result)-1)
        {
                echo "<br>\n";
        }
        else
        {
                $article_num++;
        }
}