Re: Usiing FOREACH to loop through Array

From: Date: Sat, 29 Jun 2002 23:59:10 +0000
Subject: Re: Usiing FOREACH to loop through Array
Groups: php.db php.general 
Request: Send a blank email to php-general+get-104539@lists.php.net to get a copy of this message
Oops! It's hot, it's Saturday, brain not functioning at 100%, made cut'n'paste error: <SNIP> or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID)
    global $link;
    static $result = false;
    if (!$result)
     {
       $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U,
        tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID =
        $UID", $link );
       if ( ! $result )
        die ( "getRow fatal error: ".mysql_error() );
     }
    {
    return mysql_fetch_array( $result );
    }
... while ($Row = getCourses($session[id]) as $value)
    {
    print "<br>", $Row['C.CourseName'];
    }
<SNIP> This last block of code should be while ($Row = getCourses($session[id]))
    {
    print "<br>", $Row['C.CourseName'];
    }
-steve -- +------------------------------------------------------------------------+ | Steve Edberg sbedberg@ucdavis.edu | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +------------------------------------------------------------------------+ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | +------------------------------------------------------------------------+

« previous php.general (#104539) next »