<?php $city_query = "SELECT c.cityid, c.city, COUNT(u.cityid) AS count FROM cities c LEFT OUTER JOIN user_city u ON u.cityid = c.cityid GROUP BY c.cityid ORDER BY c.city ASC"; //Taking about 0.0067 seconds and runs once $city_query = mysql_query($city_query); while($row = mysql_fetch_array($city_query)) { //INitially put this in a multidimentional array but thought that the memory leak mentioned here: //http://bugs.php.net/bug.php?id=37929 //May have been the cause //NO NULL values returned //Now they are in idividual arrays $cities[] = $row['city']; $cityid[] = $row['cityid']; $citycount[] = $row['count']; } ?> <? //get_next_start_week() allows me to get the start day for our own weekly newsletter //Query works fine after much previous testing $query = "SELECT * FROM events WHERE event_campaign_id='$id' AND date > '".date("Y-m-d H:i:s", get_next_week_start(5))."' ORDER BY date ASC"; $query = mysql_query($query); if(mysql_num_rows($query) > 0) { //Campaign Name //First Event //Last Event ?> <form action=update_promotion.php method=POST id=update_promotion name=update_promotion> <tr><td><h1>Join Weekly Nightlife Guide (Sent every Wednesday at 5am)</h1></td></tr> <tr><Td>You can add your event to our event promotion page</td></tr> <tr><Td height=10px></td></tr> <tr><td><table width="100%" cellpadding=0 cellspacing=0> <tr> <td><b>Event</b></tD> <td><b>Digital Promotion</b></tD> </tr> <? while($row = mysql_fetch_array($query)) { $ec_id = $row['ec_id']; $venueid = $row['venueid']; $name = $row['event_name']; $date = date("D dS M Y", get_date_time_stamp($row['date'])); //GET THE VENUE // Very fast query $venueqry = "SELECT venue_name, cityid FROM venues WHERE venueid='$venueid'"; $venueqry = mysql_query($venueqry); $vrow = mysql_fetch_array($venueqry); $venue = $vrow['venue_name']; $cityid = $vrow['cityid']; $promoqry = "SELECT * FROM email_promotion WHERE event_id='".$row['eventid']."' AND city_id='$cityid'"; //Again very fast $promoqry = mysql_query($promoqry); if(mysql_num_rows($promoqry) > 0) { $promorow = mysql_fetch_array($promoqry); $send_to = $promorow['to_send']; } else { $send_to = 0; } //GET THE CITY FOR THE EVENT $cityqry = "SELECT city FROM cities WHERE cityid='$cityid'"; $cityqry = mysql_query($cityqry); $crow = mysql_fetch_array($cityqry); $city = $crow['city']; ?> <tr> <Td style="height:70px; border-top:1px solid #cccccc;"><? echo $name; ?> [<a href="my_event.php?id=<? echo $row['eventid']; ?>">Edit</a>]<br><? echo $venue; ?> <? if($city != ""){ echo "<br>".$city.""; }?><br><? echo $date; ?></td> <td style="height:70px; border-top:1px solid #cccccc;">Email <input type=input id="promo_<? echo $row['eventid']; ?>" name="promo_<? echo $row['eventid']; ?>" value="<? echo $send_to; ?>"></input> members in <select id="members_<? echo $row['eventid']; ?>" name="members_<? echo $row['eventid']; ?>"> <? //SUGGESTING AN INFINITE LOOP HERE BUT CANT SEE IT for($i = 0; $i<count($cities); $i++) { echo "<option value='".$cities[$i]."' "; if($cityid[$i] == $cityid) { echo " selected"; } echo ">".$cities[$i]." (".$citycount[$i].")"."</option>"; } ?> </select> @ £10 per 1000 <select id="newsletter_<? echo $row['eventid']; ?>"> <? //Get all the wednesdays nightlife guides that this event can be added to $start_friday = get_next_week_start(5); $guide_friday = $start_friday; $start_wed = get_next_week_start(3); $guide_date = $start_wed; $event_stamp = get_date_time_stamp($row['date']) ; for($j = 0; $event_stamp >= $guide_friday; $j+=7) { $guide_date = mktime(0, 0, 0, date("m", $start_wed), date("d", $start_wed) + $j, date("Y", $start_wed)); $guide_friday = mktime(0, 0, 0, date("m", $start_friday), date("d", $start_friday) + $j, date("Y", $start_friday)); echo "<option>".date("D jS M", $guide_date)."</option>"; } ?> </select> <br><A href=#>Add More</a></td> </tr> <? } ?> <tr><td height=10px></td></tr> <tr> <td> <input type=button value="Update Promotion >" onClick ="validatePromotion();"> </td> </tr> </table></tr><td> </form> <? } else { //Support number will go in here eventually 0871 number ?> <tr><td><h1>View Events</h1></td></tr> <tr><td>You have no events running yet? Click <a href=new_campaign.php>here</a> to get started</td></tr> <? } ?> </table> As you can see from the above - the code is generally sound but for some reason it is not completing. Since making the change and moving away from a multidimentional array it is breaking on the first time it runs through the city and not "one of" the last times. The main query currently returns 19 rows and if i limit it to ten (prior to the change to single dimentional arrays) the script would finish no problem instantly. I can only think it to be memory. Paul