> I am a novice PHP dev having a strange issue with mysql_fetch_array. > For some reason, it is keeping data from previous queries in the array, > and > displaying it in the web page. > My development platform is Win2k SP2, Apache 1.3.23, PHP 4.3.0, > MySQL-MAX 3.23.47-nt. > Here is the code that I am using: > > <?php > // open database connection > $connection = mysql_connect(localhost, username, password) or die ("Unable > to > connect!"); > > // select database > mysql_select_db(vendorNameChange) or die ("Unable to select database!"); > > // generate and execute query > $query = "select * from changelog where changedBy = '$changedBy' or > vendorNumber = '$vendorNumber' > or oldName like '$oldName' or newName like '$newName' or newVendorNumber = > '$newVendorNumber'"; > $result = mysql_query($query) or die ("Error in query: $query. " . > mysql_error()); > > if ($row = mysql_fetch_array($result)) { > > do { > print "<b><u>Old vendor number</u>: </b>"; > print $row["vendorNumber"]; > print "<br>"; > <snip> > </snip> > } while($row = mysql_fetch_array($result)); > > } else {print "Sorry, no records were found!";} > > // close database connection > mysql_close($connection); > > ?> > > I am looking for a way to initialize the array, and display only the > data returned from the current query on the page. Any help with this > would > be greatly appreciated. $row = array(); will initialize the $row variable to an empty array. Or you can use unset($row) to just get rid of it entirely. The problem isn't with mysql_query(), it's just that $row is retaining data from a previous loop in your script. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php