gpt4 book ai didi

php - 为什么我的 PHP 代码不检查所需 MYSQL 表的每一行

转载 作者:行者123 更新时间:2023-11-29 23:20:05 25 4
gpt4 key购买 nike

我需要循环遍历 myn 的表,检查每一行中的其中一列(id),并在另一个表中匹配这些 id 值以获得其中称为 useragent 的值。

但目前我的 while 循环有问题,它只检查第一行的 id 值(它不会继续检查每一行)

$myarray = mysql_query("SELECT * FROM table_105");

while($row = mysql_fetch_array($myarray)){
$table = 'table_105';
$update = mysql_query("SELECT id as unp FROM $table");
$col = mysql_fetch_assoc($update);
$col_id = ($col["unp"]);

$var1 = mysql_query("SELECT useragent as ua FROM paneltb WHERE id = $col_id");
$col3 = mysql_fetch_assoc($var1);
$col_ua = ($col3["ua"]);

$browser = get_browser($col_ua, true);
$platform = $browser['platform'];
$device_name = $browser['device_name'];
$browser_name = $browser['browser'];
$version = $browser['version'];

mysql_query("
INSERT INTO table_tester(`trackerID`,`id`, `timestamp`, `useragent_browser`,`useragent_OS`,`useragent`)
SELECT `trackerID`, `id`, `timestamp`, `useragent_browser`, `useragent_OS`,'".$col3["ua"]."'
FROM $table")
or die(mysql_error());

}

最佳答案

这是因为如果您想检查所有行,则您的代码仅适用于一行,然后将内容放入 while 循环中以获取 id 和 useragent,例如:

$myarray = mysql_query("SELECT * FROM table_105");
while($row = mysql_fetch_array($myarray)){
$table = 'tracktable_105';
$update = mysql_query("SELECT id as unp FROM $table");
while($col = mysql_fetch_assoc($update))
{
$col_id = ($col["unp"]);

$var1 = mysql_query("SELECT useragent as ua FROM paneltb WHERE id = $col_id");
while($col3 = mysql_fetch_assoc($var1))
{
$col_ua = $col3["ua"];

$browser = get_browser($col_ua, true);
$platform = $browser['platform'];
$device_name = $browser['device_name'];
$browser_name = $browser['browser'];
$version = $browser['version'];
mysql_query("
INSERT INTO table_tester(`trackerID`,`id`,`timestamp`,`useragent_browser`,`useragent_OS`,`useragent`) SELECT `trackerID`, `id`, `timestamp`, `useragent_browser`, `useragent_OS`,'".$col3["ua"]."' FROM $table") or die(mysql_error());
}
}
}

关于php - 为什么我的 PHP 代码不检查所需 MYSQL 表的每一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27398587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com