首页 > 解决方案 > 查询一个 MySQL 表并将结果插入另一个表

问题描述

这是我的注释代码。

//Query the good_keywords table & pick one result at random
$result4 = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * from `good_keywords` ORDER BY RAND() LIMIT 1,1");

while($rows4=mysqli_fetch_array($result4)){ 
$tagline = $rows4['keyword'];
}
if (mysqli_num_rows($result4) > 0) {
/*Insert the one result obtained from the earlier query into `tran_term_taxonomy`.`description` provided that `tran_term_taxonomy`.`description` is empty & `tran_term_taxonomy`.`taxonomy` is 'post_tag'*/
$result2 = mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `tran_term_taxonomy` SET `description` = '{$tagline}' WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1");

echo $tagline;
 }

我面临的问题是当我运行此代码时页面甚至没有加载并且没有错误消息。我的代码有什么问题以及如何解决?

谢谢。

标签: phpmysql

解决方案


像这样的东西...

UPDATE tran_term_taxonomy x
 CROSS
  JOIN good_keywords y
   SET x.description = y.keyword
 WHERE x.taxonomy = 'post_tag'  
   AND x.description = "" 
 ORDER 
    BY RAND() LIMIT 1,1

推荐阅读