我需要遍历特定字段的每一行,抓取其内容,通过解析器运行它,然后将结果放回到字段中。我很少需要深入研究这些事情,所以我非常感激我的工作实例。这是我到目前为止的地方(请不要笑!):
<?
function parse_string($text){
// do something with $text...
return $text
}
$username="abcd";
$password="1234";
$database="abcdefg";
$table="table2"
$field="field3"
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// And for the part I'd like help with...
// Repeat through each row of $table, parsing the content of $field
// via the function parse_string($text) and placing the result back
// into the database (replacing $field)
mysql_close();
?>
答案 0 :(得分:2)
function parse_string($text){
// do something with $text...
return $text
}
$result = mysql_query("SELECT * FROM [ TABLE NAME ]");
while(($row = mysql_fetch_assoc($result)){
$myresult[] = $row;
}
array_walk( $myresult, 'parse_string' );
我建议您使用“CASE THEN”语句进行更新查询(它只是1个查询而不是下面的几个)!
UPDATE [ TABLE NAME ] SET [FIELD] = CASE `id` WHEN 1 THEN XXXXX ...... END,
[FIELD] = CASE `id` WHEN 1 THEN XXXXX ...... END,
.
.
.
.
WHERE ..........
答案 1 :(得分:0)
这是一个简单的例子:
$result = mysql_query("SELECT * FROM mytable;");
while(($row = mysql_fetch_array() != null){
echo $row["table_column"];
}
如果要有效地更改表值,则必须在查询
中执行此操作UPDATE mytables SET mycolumn = mycolumn + 1 WHERE mycolumn < 10;