[SOLVED]A for loop exceeds maximum time limit
Posted: Sat Jan 10, 2009 4:57 am
Hi everyone, this is my first technical post here in the forum. I don't touch PHP since 2005, so I'm having my bad moments.
The logic behind what I would like to achieve is: I have a table of messages dynamically generated. I want the user to be able to select one or more of those messages, then delete them. I have the checkboxes that pass an array to a method of the class "messaggi", whose object has been instantiated.
When I pass the values from the table to the method it works, and the method starts to do its job, but it exceeds the script time limit (but it does what is meant: deleting the desired messages). Here are the code snippets:
Clicking on "Cancella", $_GET['cancellaMessaggio'] = 1, so in the main script the code is:
And now, the method cancellaMessaggi():
As mentioned, the script actually works (erases what has to erase) but times out. Do you have an idea why? Thank you in advance.
The logic behind what I would like to achieve is: I have a table of messages dynamically generated. I want the user to be able to select one or more of those messages, then delete them. I have the checkboxes that pass an array to a method of the class "messaggi", whose object has been instantiated.
When I pass the values from the table to the method it works, and the method starts to do its job, but it exceeds the script time limit (but it does what is meant: deleting the desired messages). Here are the code snippets:
Code: Select all
public function visualizzaNuoviMessaggi($societa,$codiceId) {
//Dbconnection data with include omitted
//Select users and messages
$queryMessaggi = "SELECT
*
FROM
utenti_societa,utenti_messaggi
WHERE
utenti_messaggi.utenteDestinatario = '$codiceId'
AND
utenti_societa.id=utenti_messaggi.utenteMittente
AND
utenti_messaggi.letturaMessaggio = 1
";
$risultatoQueryMessaggi = mysql_query($queryMessaggi);
if (!$risultatoQueryMessaggi) {echo "La selezione messaggi non funziona";}
//Prendo i messaggi nuovi
if ($risultatoQueryMessaggi) {
//Through form action, I pass a $_GET which I'll use to trigger an if statement in the main script ?>
<table><form name="cancella" action="activeLaunch.php?cancellaMessaggio=1" method="post">
<tr id="intestazione">
<td>Selezione</td><td>Mittente</td><td>Oggetto</td>
</tr>
<?php
//Here I generate the table rows with query results
while($messaggi = mysql_fetch_array($risultatoQueryMessaggi)) {
?><tr>
<td><input type="checkbox" name="check[]" id="check[]" value="<?php echo $messaggi['idMessaggio']; ?>"></td>
<td><?php echo $messaggi['nomeUtente']." ".$messaggi['cognomeUtente'];?></td>
<td><a href="activeLaunch.php?messaggioSelezionato=<?php echo $messaggi['idMessaggio'];?>&nienteLista=1"><?php echo $messaggi['oggettoMessaggio'];?></td>
</tr>
<?php } ?>
<tr>
<td><a href="activeLaunch.php?nuovoMessaggio=1&nienteLista=1">Nuovo</a> <a href="javascript:document.cancella.submit()">Cancella</a></td><td><a href="activeLaunch.php?rispondiMittente=1">Rispondi</a></td><td><a href="activeLaunch.php?inoltraMessaggio=1">Inoltra</a> <a href="activeLaunch.php?archiviaMessaggi=1">Archivia</a></td>
</tr></form>
</table>
<?php } } //Here another method is declared....Code: Select all
if($_GET['cancellaMessaggio'] == 1) {
$check = $_POST['check'];
foreach ($check as $key => $value)
$objMessaggio->cancellaMessaggi($check);
}And now, the method cancellaMessaggi():
Code: Select all
public function cancellaMessaggi($check){
$queryRighe = "SELECT
*
FROM
utenti_messaggi
";
$risultatoQueryRighe = mysql_query($queryRighe);
$conteggioRighe = mysql_fetch_row($risultatoQueryRighe);
for($i=0;$i<$conteggioRighe;$i++){
$del_id = $check[$i];
$queryCancellazione = "DELETE FROM utenti_messaggi WHERE idMessaggio = '$del_id'";
$risultatoCancellazione = mysql_query($queryCancellazione);
if(!$risultatoCancellazione) { echo "Non riesco a cancellare il messaggio con id pari a ".$del_id;}
}