2016-04-21 8 views
2

dort von email obiger Tabelle Zahl zu berechnen und times ich will es die Zeit in Tagen hinzuzufügen nach E-Mail, aber das funktioniert nicht ..ist dieser richtige Weg Tage in PHP

<?php if(count($client)): ?> 
    <?php $days=0; 
    date_default_timezone_set('Asia/Kolkata'); 
    ?> 
    <?php foreach ($client as $clents):?> 
    <?php 
    if($clents['email']==$clents['email']){ 
    $today = time(); 
    $cdate = strtotime($clents['times']); 
    $dateDiff = $today - $cdate; 
    $fullDays = floor($dateDiff/(60*60*24)); 
    $dayscalculate = 30 - $fullDays; // Set number of days ?> 

    <?php $day=$dayscalculate; 
    $days +=$day; 
    } 
    ?> 

    <tr> 
    <td><?php echo $clents['id'];?></td> 
    <td><?php echo $clents['email'];?></td> 
    <td><?php echo $days.(($days == 1) ? " day" : " days"); ?></td> 
    <td><?php echo anchor("admin/user_view_data/{$clents['email']}",'Send Mail',array('class'=>'btn btn-info'));?></td> 
    <?php endforeach;?> 
    <?php endif; ?> 

dies nicht berechnen nach E-Mail, diese hinzugefügt ganze Wert E-Mail per E-Mail

Ich habe die gleiche E-Mail-ID mehrere Male wie [email protected] und gibt es auch mehrere wie Zeit nach E-Mail hinzufügen und E-Mail-ID nicht doppelt Eintrag anzeigen.

Ich habe keine Ahnung bitte hilf mir. Dank hier ist die Ausgabe:

+0

Das hat keinen Sinn: 'if ($ clents [ 'E-Mail'] == $ clents [ 'email'])' es immer wahr sein wird, Was wolltest du machen? –

+0

ich weiß, aber ich habe keine Ahnung? – Gnziet

+0

auch, in $ Tagen summieren Sie die Tage für alle Benutzer –

Antwort

0

Ich denke, Ihr so ​​etwas zu berechnen versucht, ist es.

wenn [email protected] Tage = 2; wieder [email protected] Tage = 5;

Sie brauchen beide von [email protected] Tage = 7;

versuchen diese

<?php if(count($client)): ?> 
 
    <?php $days=0; 
 
    date_default_timezone_set('Asia/Kolkata'); 
 

 
\t $NEW_ARRAY =array(); 
 
    ?> 
 
\t \t $i=1; 
 

 
    <?php foreach ($client as $clents) { ?> 
 
    <?php 
 
\t \t 
 
    if($i==1) 
 
\t { 
 
\t \t $today = time(); 
 
    $cdate = strtotime($clents['times']); 
 
    $dateDiff = $today - $cdate; 
 
    $fullDays = floor($dateDiff/(60*60*24)); 
 
    $dayscalculate = 30 - $fullDays; // Set number of days ?> 
 

 
    <?php $day=$dayscalculate; 
 
\t \t 
 
\t \t $NEW_ARRAY[$clents['email']]=$day 
 
\t \t \t 
 
\t \t \t // $days +=$day; 
 
\t \t 
 
\t \t 
 
    
 
    } 
 
\t else if(array_key_exists($clents['email'],$NEW_ARRAY)) 
 
\t { 
 
\t 
 
\t \t \t 
 
    $today = time(); 
 
    $cdate = strtotime($clents['times']); 
 
    $dateDiff = $today - $cdate; 
 
    $fullDays = floor($dateDiff/(60*60*24)); 
 
    $dayscalculate = 30 - $fullDays; // Set number of days ?> 
 

 
    <?php $day=$dayscalculate; 
 
\t \t 
 
\t \t $NEW_ARRAY[$clents['email']]=$NEW_ARRAY[$clents['email']]+$day; 
 
\t \t \t 
 
\t \t // $days +=$day; 
 
\t 
 
\t 
 
\t } 
 
\t else 
 
\t { 
 
\t 
 
\t \t $today = time(); 
 
    $cdate = strtotime($clents['times']); 
 
    $dateDiff = $today - $cdate; 
 
    $fullDays = floor($dateDiff/(60*60*24)); 
 
    $dayscalculate = 30 - $fullDays; // Set number of days ?> 
 

 
    <?php $day=$dayscalculate; 
 
\t \t 
 
\t \t $NEW_ARRAY[$clents['email']]=$NEW_ARRAY[$clents['email']]+$day; 
 
\t \t \t 
 
\t \t // $days +=$day; 
 
\t 
 
\t 
 
\t 
 
\t } 
 
\t 
 
\t $i++; 
 
    }

+0

Ihre Logik ist korrekt, aber zuletzt sonst Bedingung mit Fehler $ $ NEW_ARRAY [$ Clents ['E-Mail']] = $ NEW_ARRAY [$ Clents ['E-Mail']] + $ Tag ; 'mit einigen E-Mail-ID – Gnziet

+0

zeigt undefined Index – Gnziet

+0

letzte sonst Bedingung Sie ändern nur die Tage Zähllinie wie diese $ NEW_ARRAY [$ Clents ['E-Mail']] = $ Tag; weil diese Mail-ID einen neuen Eintrag hat, so dass du diesen als neuen Eintrag speichern musst. – JYoThI

0

Dies ist ein Beispiel dafür, wie die Differenz zwischen zwei Daten zu erhalten: Vom ersten Bild (Datenbanktabellen), nahm ich das Beispiel der ID: 17

$today = new DateTime("now"); 
$clientDateString = $clents['times']; 
$clientDate = date_create($clientDateString); 

$dateInterval = date_diff($clientDate, $today); 
echo $dateInterval->format('%d'); 
0

Versuchen Sie diese, um die Tage zu berechnen, wenn das Datum ohne die Zeit eingegeben wird.

$to_date = strtotime($to_date); 
$from_date = strtotime($from_date); 
$datediff = $to_date - $from_date; 
$days = $datediff/(60 * 60 * 24) + 1; 

Hoffe, das wird Ihnen helfen.

0

Versuchen Sie dies, wenn ich verstanden habe:

<table> 
<?php 

if(count($client)): 
    $days = 0; 
    $today = time(); 
    date_default_timezone_set('Asia/Kolkata'); 

    $all_clients = array(); // This array will contain the final data 

    foreach ($client as $clents): 

     $cdate = strtotime($clents['times']); 
     $dateDiff = $today - $cdate; 
     $days = 30-floor($dateDiff/(60*60*24)); 

     if(!isset($all_clients[$clents['email']])) 
     { 
      // This cliens is already in the array, add the number of days 
      $all_clients[$clents['email']] = [ 
       'id' => $clents['id'], 
       'email' => $clents['email'], 
       'days' => $days, 
      ]; 
     } 
     else 
     { 
      // Add the new days to the existing 
      $all_clients[$clents['email']]['days'] += $days; 
     } 

    endforeach; 


    foreach($all_clients as $client): 
     ?> 
     <tr> 
     <td><?php echo $client['id'];?></td> 
     <td><?php echo $client['email'];?></td> 
     <td><?php echo $client['days'] . (($client['days'] == 1) ? " day" : " days"); ?></td> 
     <td><?php echo anchor("admin/user_view_data/{$client['email']}", 'Send Mail', array('class'=>'btn btn-info'));?></td> 
     </tr> 
     <?php 
    endforeach; 
endif; 

?> 
</table> 
+0

sie zeigen einige Fehler in Ihrem Array-Format – Gnziet

+0

ok Ich habe es bearbeitet, es ist weil Sie eine alte Version von PHP verwenden –

+0

Wert für den Wert nicht hinzugefügt dort Wert der anderen ist der gleiche Wert nur eine E-Mail-Wert zeigt – Gnziet

Verwandte Themen