让我们直接解决问题......我有这张表,名为 'phonenumber' :
+-------------+
| phonenumber |
+-------------+
| 555-123456 |
| 555-999999 |
| 555-888888 |
+-------------+
现在,我想通过将消息插入到名为“发件箱”的表中来向这些号码发送短信:
+------+----------------+---------------------------------------------+
| ID | phonenumber | message |
+------+----------------+---------------------------------------------+
| ...... |
| 321 | 555-123456 | part 1 : lorem ipsum dolor sit amet |
| 322 | 555-999999 | part 1 : lorem ipsum dolor sit amet |
| 323 | 555-888888 | part 1 : lorem ipsum dolor sit amet |
+------+----------------+---------------------------------------------+
很容易做到这一点。这个 SQL 可以完成这项工作:
INSERT INTO outbox (phonenumber, message)
SELECT phonenumber, '$SMSMessage' as message
FROM phonenumber
WHERE purchasedate BETWEEN 2012-01-01 AND 2012-01-31;
当短信超过 160 个字符时,问题就出现了。它需要被拆分,在这种情况下,拆分消息的第二部分必须存储在名为“outbox_multipart”的其他表中,并保留“发件箱”中的 ID 号,以便该表如下所示:
+------+----------------+----------+----------------------------------+
| ID | phonenumber | outboxID | message |
+------+----------------+---------------------------------------------+
| ...... |
| 1025 | 555-123456 | 321 | part 2 : hello there! |
| 1026 | 555-999999 | 322 | part 2 : hello there! |
| 1027 | 555-888888 | 323 | part 2 : hello there! |
+------+----------------+---------------------------------------------+
请注意:outbox.ID 与 outbox_multipart.outboxID 相关。
我有这个 PHP 循环来插入文本消息:
foreach ($CutMessage as $index => $SMSMessage)
{
if ($index == 0) {
**INSERT FIRST PART OF MESSAGE TO OUTBOX TABLE**
}else{
**INSERT SECOND / OTHER PART OF MESSAGE TO OUTBOX_MULTIPART TABLE**
}
}
如何用 PHP 正确地做到这一点?谢谢你。