这是代码片段:
$check = mysql_query("SELECT occurrence_number FROM occurrence WHERE word_id = '$word_id' AND page_id = '$page_id'");
$array_row = mysql_fetch_array($check);
if($array_row['occurrence_number']){
mysql_query("UPDATE occurrence SET occurrence_number = occurrence_number +1 WHERE word_id = '$word_id'");
print "Updating";
}else{
mysql_query("INSERT INTO occurrence (word_id,page_id) VALUES ($word_id,$page_id)");
print "Indexing: $cur_word<br>";
}
我希望查询执行的操作:
如果在 tableoccurrence
中存在word_id ='$word_id'
和的行page_id = '$page_id'
,则在向其添加 1 后更新该occurrence_number
行的该列。
执行此查询时得到的结果:
代码从不进入if
子句。每次我执行代码时,都会生成一个新行word_id
,其page_id
默认值occurrence_number
(设置为0
)和 occurrence_id
(自动递增和主键)相同。