gpt4 book ai didi

php - 使用 php 比较两个 mysql 记录集

转载 作者:行者123 更新时间:2023-11-30 01:37:53 25 4
gpt4 key购买 nike

我需要使用 php 比较两个 mysql 记录集

比较第一个记录集中的记录是否存在于第二个记录集中,并返回 true 值,如果不存在则返回 false。

问题是一旦对记录集进行了一次传递,它就不会返回到开头,因此我可以将 recordset1 的剩余记录与其进行比较。

我使用的代码是:

*mysql_select_db($database_db, $db);

$query_rec_teams = "SELECT tbl_items.* FROM tbl_items;";
$rec_items = mysql_query($query_rec_items, $db) or die(mysql_error());

$row_rec_items = mysql_fetch_assoc($rec_items);
$totalRows_rec_items = mysql_num_rows($rec_items);

$query_rec_itemsLeft = "(SELECT tbl_itemsleft.* FROM tbl_itemsLeft";
$rec_itemsLeft = mysql_query($query_rec_itemsLeft, $db) or die(mysql_error());
$row_rec_itemsLeft = mysql_fetch_assoc($rec_itemsLeft);
$totalRows_rec_itemsLeft = mysql_num_rows($rec_itemsLeft);

//iterate first recordset, populate variables
do{
$itemPresent=0;
$item=$row_rec_item['ItemID'];
//iterate second recordset and compare item variable with itemID fields in recordset, if exist echo true, else echo false
do {
if ($row_rec_itemsLeft(['ItemID'] == $item){
itemPresent=1;
}
else{
itemPresent=0;
}
echo itemPresent;
} while ($row_rec_itemsLeft = mysql_fetch_assoc($rec_itemsLeft));

} while ($row_rec_items = mysql_fetch_assoc($rec_items));

mysql_free_result($rec_itemsLeft);
mysql_free_result($rec_items);
?>*

将记录集填充到数组中并比较数组会更容易吗

感谢帮助

最佳答案

使用 MYSQL JOIN 检索结果。

请引用此链接进行连接..

http://www.sitepoint.com/understanding-sql-joins-mysql-database/

关于php - 使用 php 比较两个 mysql 记录集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16609241/

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