Problema Division by zero
-
Buongiorno a tutti
Chiedo un aituo per una formula php che in alcuni casi da risultato 0 e mi da un errore "Division by zero".
Posto il codice per favore potete aiutarmi a risolvere il problema?
Grazie a tutti per aiuto
Buonasera
$click_active_bought=mysql_fetch_assoc(mysql_query("SELECT (SUM(plan)) AS total_click_active_bought FROM yob_ads WHERE user <> 'admin' AND ads_category = 'click' AND status = 'active'")); $click_active_sent=mysql_fetch_assoc(mysql_query("SELECT (SUM(members)) AS total_click_active_sent FROM yob_ads WHERE user <> 'admin' AND ads_category = 'click' AND status = 'active'")); $click_active_available=mysql_fetch_assoc(mysql_query("SELECT (SUM(plan-members)) AS total_click_active_available FROM yob_ads WHERE user <> 'admin' AND ads_category = 'click' AND status = 'active'")); <tr> <th width="250">Total Click Active Sold</th> <td> <b><font color='blue'><?php echo $click_active_bought[total_click_active_bought]; ?> </b> </font> (<?php echo round(($click_active_bought[total_click_active_bought]/$click_active_bought[total_click_active_bought]*100),2); ?>%) </td> </tr> <tr> <th width="250">Total Click Active Sent</th> <td> <b><font color='green'><?php echo $click_active_sent[total_click_active_sent]; ?> </b> </font> (<?php echo round(($click_active_sent[total_click_active_sent]/$click_active_bought[total_click_active_bought]*100),2); ?>%) </td> </tr> <tr> <th width="250">Total Click Active Available</th> <td> <b><font color='red'><?php echo $click_active_available[total_click_active_available]; ?> </b> </font> (<?php echo round(($click_active_available[total_click_active_available]/$click_active_bought[total_click_active_bought]*100),2); ?>%) </td> </tr> -
Ciao guadagnaeuro,
dovresti fare in modo che $click_active_bought[total_click_active_bought] abbia come valore minimo 1.
if($click_active_bought[total_click_active_bought] == 0) $click_active_bought[total_click_active_bought] = 1;
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi