あなたが助けてくれることを願っています。
2 つの部分を実行するスクリプトがあります。上部は行を返さず、行を返す場合は、INSERT および UPDATE クエリが実行されます。
2 番目の部分は、論理的に同じことを行います。
上部が行を返さない場合、スクリプトの 2 番目の部分は正常に動作します。
しかし
上部が行を返す場合、スクリプトの 2 番目の部分では UPDATE クエリのみが実行され、INSERT は実行されません (エラーは発生しません)。
問題は何ですか?これは本当に私を悩ませ始めています。
ここにスクリプトがあります
<?php
require_once('function.sendtxt.php');
$now = time();
$received = date("Y-m-d H:i:s", $now);
mysql_connect("x", "x", "x") or die(mysql_error());
//echo "Connected to MySQL<br />";
mysql_select_db("x") or die(mysql_error());
//echo "Connected to Database<br />";
//$a = array();
//$a[] = array("id=0", "text");
$txt = 'We have cancelled your order as we have not heard back from you in a while. To order, please resend your request';
// those orders not complete over 30 minutes
$select = mysql_query("
SELECT id, received, txtus, link, sender
FROM incoming_texts
WHERE id IN (
SELECT i3.id FROM (
SELECT DISTINCT i2.link as link, max(i2.id) as id
FROM incoming_texts i1
JOIN incoming_texts i2 ON i1.id = i2.link
WHERE (i1.link = 0)
GROUP BY i2.link ASC
) i3
)
AND TIMESTAMPDIFF(MINUTE, received, now()) > 30
") or die(mysql_error());
if (mysql_num_rows($select) > 0) {
while ($row = mysql_fetch_array($select)) {
// id, received, txtus, link, sender
$id .= "," . $row["id"];
$txtus = $row["txtus"];
$link = $row["link"];
$from = $row["sender"];
//$received = $row["received"];
//echo $id;
// cancel the row
mysql_query("
INSERT INTO incoming_texts
(txtus, sender, msg, received, this_step, next_step, link)
VALUES
(".$txtus.", ".$from.", 'cancel_inactive_text_orders.php 1', '".$received."', 'cancel', 'order', $link)
") or die('Error: ' . mysql_error());
//sendtxt($txtus, $from, $txt);
}
// -2 = cancelled
mysql_query("
UPDATE incoming_texts
SET link = -2
WHERE link IN (00".$id.")
") or die(mysql_error());
}
/*
below is the second part
*/
$link0 = mysql_query("
SELECT id, received, txtus, link, sender
FROM incoming_texts
WHERE (
link = 0
AND TIMESTAMPDIFF(MINUTE, received, now()) > 30
)
") or die(mysql_error());
if (mysql_num_rows($link0) > 0) {
while($row = mysql_fetch_array($link0)) {
// id, received, txtus, link, sender
$id = $row["id"];
$txtus = $row["txtus"];
$link = $id;
$from = $row["sender"];
//$received = $row["received"];
$link0rows = mysql_query("
SELECT id
FROM incoming_texts
WHERE link = ".$id."
LIMIT 1
") or die(mysql_error());
if (mysql_num_rows($link0rows) < 1) {
mysql_query("
UPDATE incoming_texts
SET link = -2
WHERE (id = $id)
") or die(mysql_error());
mysql_query("
INSERT INTO incoming_texts
(txtus, sender, msg, received, this_step, next_step, link)
VALUES
(".$txtus.", ".$from.", 'cancel_inactive_text_orders.php 2', '".$received."', 'cancel', 'order', $id)
") or die(mysql_error());
//echo $id . " ";
//sendtxt($txtus, $from, $txt);
} // if
} // while
} // if
mysql_close();
?>