如何从mysql中提取特定的细胞(细胞列);某事“;然后保存在同一个地方


How to extract specific cell (column of cells) from mysql, do "something" on it and save in the same place?

我有一个phpbb论坛3.0.5(使用php和mysql)
我想从数据库中只提取"主题"answers"帖子"单元格,并用谷歌翻译内容,然后将翻译后的内容保存(重写)到数据库中的同一位置。这能做到吗?

如果没有,你能告诉我如何只导出特定的表内容吗?

以下示例:

1 2 3 4 5 6
a b c d e f 
g h i j k l

我只想导出包含所有值(e,k,…)的第5列,而不导出sql特定的标记——只导出文本。

请帮忙。提前谢谢。

您可以对有问题的表运行以下查询,只得到所需的列:

$sql = "SELECT `id`, `column_name` FROM `table_name` LIMIT 0, 30 ";

这将从表中的所有内容中为您提供请求的列。然后,您可以通过以下查询查看结果,转换它们并将它们重新插入数据库:

$sql = "UPDATE `database_name`.`table_name` SET `column` = 'new translated content'' WHERE `table_nane`.`id` = the_proper_id;";

因此,基本上,您可以提取所有需要更改的值,逐一检查它们,在数据库中转换和更新它们。

要选择一列,请执行以下操作:

SELECT columnName FROM tableName

然后根据需要操作数据并保存:

$query = mysql_query("SELECT id,columnName FROM tableName"); // You need ID field for reference
while($row = mysql_fetch_assoc($query) {
   $field = $row["columnName"];
   // Do Something with the Field Data
   // ...
   // ...
   // Update the Table with new values
   $update = "UPDATE tableName SET columnName = '".$field."' WHERE id = '".$row['id']."'");
   mysql_query($update); // This update the field with what you set in "$field"
}

//了解更多:

SELECT语法

UPDATE语法

具体来说:1.启动数据库连接。2.使用我之前指定的查询从表中获取所有信息:

$sql = "SELECT `id`, `column_name` FROM `table_name` ";

要运行此查询,请执行以下操作:

  $query_results = $database_connection->query($sql);//this will run the query and get all the results, check to make sure it all worked:
 if(!$query_results){
 echo "There was a problem: ".$db_connection->error;
} else { 
//the query worked so this is what we do
//get the number of results
$result_number = $query_results->num_rows;//the number of results
$result_info = $query_results->fetch_assoc();//getting the information from the first result
//looping through:
for($i = 0; $i < $result_number; $i++){
$value_to_convert = $result_info['needed_column'];
//do what ever you want to the value_to_convert - also - needed_column is the name of the column you need.
//insert the new value back into the database:
$sql = "UPDATE `database_name`.`table_name` SET `column` = 'new translated content'' WHERE ``table_nane`.`id` = the_proper_id;";
//run it:
$update_query = $db_connection->query($sql);
//check like before
if(!$update_query){

 echo "There was a problem updating: ".$db_connection->error
} 
//get the next result:
$result_info = $query_results->fetch_assoc();//getting the information from the first result
}
}