Steve McGill wrote:
"Jeffrey Baumgartner" <jeffreyb@xxxxxxxxxxx> schreef in bericht
news:4226F88A.9020504@xxxxxxxxxxxxxx
I've made a little programme that deletes expired records from database
tables. The troublesome bit looks like this...
$query = "SELECT ic FROM ic_ic WHERE date <= CURDATE()";
$result = mysql_query($query) or die("Unable to get old
campaigns because " . mysql_error());
while ($row = mysql_fetch_array($result)){
extract($row);
...delete records from tables where ic = ic
are you by any chance doing a query inside this while loop?
if you are then make sure you assign the result of the call to mysql_query()
to a variable that is NOT called $result.
}
It works fine for the fitst value of $ic, but on the second time around
I get an error message saying that line [starting with "while..."] is
not a valid MySQL resource. This really puzzles me because it works one
time around, but not after that.
print_r(), var_dump() (and plain echo or print) are your friends:
if you preceed the line starting 'while ($row =' with the following:
var_dump( $result );
and then also add such a statement at the bottom of your while code ie:
var_dump( $result );
while ($row = mysql_fetch_array($result)) {
extract($row); // not a good idea IMHO
// do your stuff
var_dump( $result );
}
then you should see it change on the second call to var_dump(), which
will hopefully lead you to the code that changes the $result var when
you don't want it to change.
$ic, incidentally, is a string originally generated from the timestamp
(ie. getdate[0]) - could this be causing a problem?
Why don't you try it without using extract($row), and use $row[variable1]
$row[variable2] instead in your loops.
extract() pulls all the variables into the global namespace and can be quite
dangerous as it might overwrite other variables. (this might be whats
happening with the $result variable for example.
also, how does extract() behave when trying to convert the [0] [1] [2]
variables? you might be better off using mysql_fetch_assoc()
ditto, dont extract() in this situation - its a waste of a function call and a
waste of variable initialization... just use the values in the $row array directly... e.g.
echo $row['ic']; // this could have been $ic if you had called extract($row)
Best wishes,
Steve
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php