我需要遍历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());
}
答案 0 :(得分:0)
因为你的代码只有一行,如果你想检查所有行然后将你的内容放在内部,而循环中的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());
}
}
}