|
Posted by ByteCoder on 09/27/05 11:37
Is it possible to change the value in a resultset? An example (why is
this not possible and is there a way around it?)
<?php
// Connect to the database.
require_once('includes/db_connect.inc');
// Get data from the table 'user'.
$query = "select username from user";
$result = mysql_query($query);
// Print the results.
while($row = mysql_fetch_array($result)) {
$username = $row['username'];
print("$username<br />");
// Try to change the value of the username.
$row['username'] = "1";
$username = $row['username'];
print("$username<br />"); }
// Reset the pointer of the result to the beginning.
mysql_data_seek($result,0);
// Print the result again.
while($row = mysql_fetch_array($result)) {
$username = $row['username'];
print("$username<br />");
}
?>
It does print the "1" after each username just as I had expected, but
when the $row array gets out of scope it is gone. Is there a way to put
the modimied $row back into the $result?
I want to do this because I don't want the writer of a web page to have
to bother about stripslashes() and the like. In that scenario the writer
of the web page would execute a function to get the contents of a table.
I would then get the result, do a stripslashes on the columns that need
it, reset the pointer to the first row and then return the result.
TIA,
--
----------------------------------
- ByteCoder -
- "Da Evul Dootchie" -
- Qnl0ZUNvZGVyQHBsYW5ldC5ubA== -
----------------------------------
Navigation:
[Reply to this message]
|