我想从此输出中获取ID并更新数据库,如何从该查询中获取ID?

$text = "<test>output: 1;outdoor: 456;<test>
    <test>output: 2;outdoor: 4564;<test>
    <test>output: 3;outdoor: 645;<test>
    <test>output: 4;outdoor: 765;<test>";

mysql_query("UPDATE test SET outdoor = $outdoor" where id = $output);

最佳答案

请尝试我的答案

<?php
    $text = "<test>output: 1;outdoor: 456;<test>
    <test>output: 2;outdoor: 4564;<test>
    <test>output: 3;outdoor: 645;<test>
    <test>output: 4;outdoor: 765;<test>";
    $text_arr = explode("\n",$text);

    foreach($text_arr as $val_text_arr){
        /*echo $val_text_arr."<bR>";*/
        $output = explode(";",explode("output: ",$val_text_arr)[1])[0];
        echo "output ".$output ."\n";
        $outdoor = explode(";",explode("outdoor: ",$val_text_arr)[1])[0];
        echo "outdoor ".$outdoor ."\n";
        /*you can update here ypur query*/
        mysql_query("UPDATE test SET outdoor = $outdoor" where id = $output);
    }
     ?>


输出:

output 1
outdoor 456
output 2
outdoor 4564
output 3
outdoor 645
output 4
outdoor 765


PHP的链接,我试试这个
https://eval.in/872778

关于php - 我如何获得输出ID和更新表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46541646/

10-16 11:04
查看更多