我编写了一个 PHP 脚本,它连接两个表以这种格式显示信息:
Jane Doe
Phone: 082 980 9514
Home Loan Applications (Active) - 17/07/2013
Credit Report (Free Report) (Unsubscribed) 12/06/2013
您会注意到 firstname 和 lastname 在输出的第一行,然后是电话号码,然后是他们订阅的邮件列表。列表旁边是状态。活动表示用户尚未取消订阅并且仍然处于活动状态,如果用户已经选择退出邮件列表,则会显示取消订阅的日期。然后是订阅者注册到某个邮件列表的日期。
这是示例表的链接:表
它可以正常工作,但需要很长时间才能完成,因为一个表中有大约 76,000 条记录,另一个表中有大约 100,000 条记录。我想就如何优化代码以加快脚本速度提出建议。
这是我编写的当前代码:
$resultarray = array();
$rs4 = mysqli_query($con1,"SELECT interspire_customfield.subscriberid, interspire_customfield.fname, interspire_customfield.lname, interspire_customfield.phone, emailaddress, subscribedate, unsubscribed, interspire_customfield.listid, listname FROM `interspire_subscriber` INNER JOIN `interspire_customfield` ON interspire_subscriber.subscriberid = interspire_customfield.subscriberid GROUP BY emailaddress");
while($row4 = mysqli_fetch_array($rs4)) {
$resultarray[] = $row4['subscriberid'].",".$row4['fname'].",".$row4['lname'].",".$row4['phone'].",".$row4['emailaddress'];
}
foreach ($resultarray as $arrlist) {
$arr = explode(',', $arrlist);
$sid = $arr[0];
$frstname = $arr[1];
$lstname = $arr[2];
$pnum = $arr[3];
$emailadd = $arr[4];
echo $frstname." ".$lstname."<br />";
echo "Phone: ".$pnum."<br />";
$rs5 = mysqli_query($con1,"SELECT interspire_customfield.subscriberid, subscribedate, unsubscribed, interspire_customfield.listid, listname FROM interspire_subscriber INNER JOIN interspire_customfield ON interspire_subscriber.subscriberid = interspire_customfield.subscriberid WHERE interspire_subscriber.emailaddress = '$emailadd' GROUP BY interspire_subscriber.listid");
if (!$rs5) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
while($row5 = mysqli_fetch_array($rs5)) {
$listname = $row5['listname'];
$subdate = $row5['subscribedate'];
$unsub = $row5['unsubscribed'];
if($unsub == "0"){
$stat = "Active";
}else{
$stat = date('d/m/Y', $unsub);
}
$subdt = date('d/m/Y', $subdate);
echo "* $listname ($stat) - $subdt <br />";
}
echo "<br />";
}