我为以下脚本开发了foreach函数
function kali($src, $key, $pengali)
{
echo $pengali . ' x ' . $src . ' = ' . $pengali * $src . '<br/>';
}
$tampil = mysql_query(" SELECT DISTINCT term FROM `term` order by term ");
while ($t = mysql_fetch_array($tampil)) {
$term = $t[term];
$array = array();
$tampil2 = mysql_query(" select term, id_document, wdt from wdt where term = '$term' order by id_document ");
while ($t = mysql_fetch_array($tampil2)) {
$term = $t[term];
$id_document = $t[id_document];
$wdt = $t[wdt];
$wdt_r = round($wdt, 2);
$array[] = $wdt_r;
}
foreach ($array AS $item => $value) {
$temporary = array_shift($array);
array_walk($array, 'kali', $value);
}
}
我想将foreach函数id_document
和term中计算的乘法结果保存到数据库中。
我可以在这里得到一点帮助吗?
答案 0 :(得分:0)
运行查询以在完成计算后将数据插入数据库:
mysql_query("INSERT INTO table_name (id_document, term) VALUES ($id_document, $term)");
让我知道它是怎么回事