MySQL Query需要很长时间才能显示

时间:2014-03-04 20:44:33

标签: php mysql

以下代码有效但页面加载需要几分钟。基本上,我正在查询数据库中是否有任何即将发生的事件,并且总计了每个事件的数量列。活动少于30场,每场比赛平均有30张门票。

感谢。

<?php

$rowsquery="SELECT *
FROM listings
WHERE show_date > DATE_SUB(CURDATE(), INTERVAL 3 DAY)
ORDER BY show_date";
$result=mysql_query($rowsquery);

$num=mysql_numrows($result);

mysql_close();

?>


<?php
$i=0;
while ($i < $num) {

$item_number=mysql_result($result,$i,"item_number");
$show_date=mysql_result($result,$i,"show_date");
$show_time=mysql_result($result,$i,"show_time");
$headline=mysql_result($result,$i,"headline");
$double_head=mysql_result($result,$i,"double_head");
$price=mysql_result($result,$i,"price");
$opening_stock=mysql_result($result,$i,"opening_stock");
$available_online=mysql_result($result,$i,"available_online");
$booking_fee=mysql_result($result,$i,"booking_fee");
$total_price=$price+$booking_fee;

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$total = "SELECT SUM(i.quantity) as total_tickets 
FROM paypal_ipn_orders o, paypal_ipn_order_items i
WHERE i.item_number = '$item_number'
AND i.raw_log_id = o.raw_log_id
AND o.payment_status != 'Refunded'
ORDER BY UPPER(o.last_name)";
$sRow = mysql_fetch_array(mysql_query($total));
$totaltkts = $sRow['total_tickets'];

mysql_close();
?>

1 个答案:

答案 0 :(得分:0)

确保在where子句中的所有字段中都有数据库索引 - item_number,raw_log_id,payment_status