This should be easy:
I have a query result set and I've already used the results of the set. How do I then get rid of the result set from that query later on in the same script?
It's obviously not mysql_free_result. Any function I'm missing?
Thanks, Ruth
Closing a result set
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
kill result set
I want to kill the result set, so I can't even echo any data from it. mysql_free_result just releases the memory, but the result set still exists.
From the PHP manual:
Example 1. A mysql_free_result() example
From the PHP manual:
Example 1. A mysql_free_result() example
Code: Select all
<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
/* Use the result, assuming we're done with it afterwords */
$row = mysql_fetch_assoc($result);
/* Now we free up the result and continue on with our script */
mysql_free_result($result);
echo $rowї'id'];
echo $rowї'email'];
?>-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
not sensitive -- just in the way...
This is for a calendar of upcoming events. The common header for the entire site calls a SQL statement and then displays the next upcoming event (this is the original result set).
One script on the site is the form to input new events. The first time a user sees the form it should not be populated -- then if there's a validation issue, the form reappears with the user's POST information (so there's a 'value = $variable' statement in each form field).
The problem is that the first time the user sees the form, it's populated with the record from the result set in the header.
I attempted to overwrite the results by setting up a new SQL statement that would pull 0 records using the same variable names that are in the header request, but it didn't work.
Any suggestions?
Thanks, Ruth
One script on the site is the form to input new events. The first time a user sees the form it should not be populated -- then if there's a validation issue, the form reappears with the user's POST information (so there's a 'value = $variable' statement in each form field).
The problem is that the first time the user sees the form, it's populated with the record from the result set in the header.
I attempted to overwrite the results by setting up a new SQL statement that would pull 0 records using the same variable names that are in the header request, but it didn't work.
Any suggestions?
Thanks, Ruth
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Give the variables different names? When passing the variables back to the form if there was an error call the fields 'err_name', 'err_event' etc. And you should really also pass back a variable called 'error' or something similar and then you can check to see if there was an error and know if you should populate the field.