如何使用不同行中的变量回显输出

问题描述 投票:0回答:1

我有在str_split()上使用12345678910返回12 34 56 78 91 0的代码。

我的问题是当我尝试更新数据库时,更新了错误的数据。

我在页面上回显它并输出错误的数据。

另外,我该如何解决这个问题?

这是我的代码:

require("init.php");
$code = "12345678910";
$type = "2";
$disp = str_split($code, $type); 
for($b = 0; $b<$type; $b++){
    $show = "$disp[$b]";
}
for($c = $qty; $c<sizeof($disp); $c++){
    $play = "$disp[$c]"; 
    $id = "7"; 
    mysqli_query($conn, "UPDATE prmo SET details='$show$play' WHERE id=$id");
    echo "<br/>$show";
    echo "<br/>$play";
}

我的结果与当前的代码是56 34 78 34 91 34 0 34预计是12 34 56 78 91 0我能真正实现这一目标吗?

php output echo
1个回答
0
投票

你在这里做错了是,你正在从2个循环遍历。你只需要循环。尝试以下代码:

$code = "12345678910";
$type = "2";
$disp = str_split($code, $type); 
for($c = 0; $c<sizeof($disp); $c++){
    $show = $disp[$c];
    $c++;
    $play = $disp[$c]; 
    $id = "7"; 
    mysqli_query($conn, "UPDATE prmo SET details='$show$play' WHERE id=$id");
    echo $show." ";
    echo $play." ";
}
© www.soinside.com 2019 - 2024. All rights reserved.