You are here: Change value in result « PHP Programming Language « IT news, forums, messages
Change value in result

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация