2016-04-07 15 views
-2

Sorunun zaten yanıtlandığını biliyorum ama bence karmaşıklık biraz yüksek. 5 sütunlu bir tablom var, satırlar herhangi bir sayı olabilir. Veritabanından alınan veriler belirli bir koşula dayanmaktadır ve çıktı sıralıdır. Yapmam gereken şey, db tarafından yan yana alınan 2 satırı görüntülemem gerekiyor, sonuç olarak toplamda 10 sütunumuz olacak. Bunu tüm satırlar için yapmalıyım. Yani db'de 10 satır varsa, her ikinci sıraya yerleştirilirken php üzerinde 5 satır olacaktır.php olarak 2 satırı yan yana görüntüler ve yeni bir alandaki zaman farkını gösterir

Şimdi, şey beşinci ve onuncu sütun unix zaman damgası geçiriyor. 10 sütunundaki unix zaman damgasından beşinci sütundaki unix zamanını çıkarmalı ve bir PHP ekranındaki 11 sütununda bir fark olarak göstermeliyim. Yazdığım kod tüm sıraları sırayla görüntüler. Bunu nasıl yapacağımdan emin değilim. Yardıma ihtiyacım var! // Bir geliştirici değilim Performans testine katılıyorum. Sadece bunu yapmalıyım .. :(.. Lütfen PHP kodumu (Database snap enter image description here) (Beklenen çıkış enter image description here) 'dan bekledikten sonra 10'üncü sütundan sonra beklenen bir fark sütununa ihtiyacım var. ... ve beşinci sütun şimdiden teşekkür ederiz ..

<?php 

include '_runQuery.php'; 


$host="10.139.157.84"; 
$username="testadmin"; 
$password="summer12"; 
$db_name="pvteamdb"; 

$printLimit = 100000; 


// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

// Get values from form 

$application =$_POST['application']; 
$lifecycle =$_POST['lifecycle']; 
$useability =$_POST['useability']; 


// 'application' needs to have a value ... 

if ($application == "") { 
    echo "<br><br> *ERROR: you must enter an application id !! ** " ; 
    echo "<br><br><a href='print_selected_policies.php'>Back</a>"; 
    return; 
} 



$sqlfirstbit = "SELECT application,identifier,lifecycle,useability,epochtime FROM policies WHERE application = '$application'"; 
$orderByStmt = " order by identifier asc"; 

if ($lifecycle == "" && $useability == "" ){ 
    $sql = $sqlfirstbit . $orderByStmt; 
} else if ($useability == ""){ 
    $sql = $sqlfirstbit . " AND lifecycle = '$lifecycle' " . $orderByStmt; 
} else if ($lifecycle == ""){ 
    $sql = $sqlfirstbit . " AND useability = '$useability' " . $orderByStmt; 
} else { 
    $sql = $sqlfirstbit . " AND lifecycle = '$lifecycle' AND useability = '$useability' " . $orderByStmt; 
} 

$result=runQuery($sql); 

$numRows=mysql_num_rows($result); 
echo "<br><br> numRows = ". $numRows; 


if ($numRows > $printLimit){ 
    echo "<br><br> *ERROR: more than $printLimit rows have been returned from query ($numRows rows returned)** " ; 
    echo "<br><br><a href='print_selected_policies.php'>Back</a>"; 
    return; 
} 


if ($numRows == 0){ 
    echo "<br><br> -- No rows match filter criteria -- "; 

} else { 
    echo "<table border='1'>"; 

    echo "<tr><td>application</td><td>identifier</td><td>lifecycle</td><td>useability</td><td>epochtime</td></td>"; 
    echo "</tr>"; 

     // $rows=mysql_fetch_array($result); 

    while ($row = mysql_fetch_assoc($result)){ 
     $application= $row['application']; 
     $identifier = $row['identifier']; 
     $lifecycle = $row['lifecycle']; 
     $useability = $row['useability']; 
      //$otherdata = htmlspecialchars($row['otherdata']); 
      //$otherdata =$row['otherdata']; 
      //$lifecycle = $row['lifecycle']; 
     //$created = $row['created']; 
     //$updated = $row['updated']; 
      $epochtime = $row['epochtime']; 

     echo "<tr>"; 
     echo "<td>$application</td>"; 
     echo "<td>$identifier</td>"; 
     echo "<td>$lifecycle</td>"; 
     echo "<td>$useability</td>"; 
     //echo "<td>$otherdata</td>"; 
     //echo "<td>$created</td>"; 
     //echo "<td>$updated</td>"; 
      echo "<td>$epochtime</td>"; 
     echo "</tr>"; 
    } 
    echo "</table>"; 
    mysql_free_result($result); 

}`enter code here` 

echo "<br><br><a href='message_analyzer.php'>Back</a>"; 
mysql_close(); 

?> 
+2

sorunu çoğaltmak için zor yeterli ayrıntıları sağlamadan gerekli tüm ayrıntıları ekleyiniz gerekli ayrıntıları şunları içerir: 'senin ilişkili tablolar, örnek veriler, beklenen çıkışı Şimdiye kadar ne denediniz? Teşekkür ederiz. – 1000111

+0

Veri tabanına eklendi – user3514283

+0

Yorumla beklenen çıktı eklendi. – user3514283

cevap

0
<html> 
    <head> 
     <title>EMBS_AON</title> 
     <link rel="stylesheet" href="style.css" media="all"> 
    </head> 

    <body> 
     <div id="container"> 


      <?php 

$host="10.139.157.84"; 
$username="testadmin"; 
$password="summer12"; 
$db_name="pvteamdb"; 

$printLimit = 100000; 

// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

$application =$_POST['application']; 
$lifecycle =$_POST['lifecycle']; 
$useability =$_POST['useability']; 

       include '_runQuery.php'; 
       $query = "SELECT application,identifier,lifecycle,useability,created,updated,epochtime FROM policies WHERE application = '$application' AND useability = '$useability' "; 
           $orderByStmt = " order by epochtime asc"; 
       $run = mysql_query($query); 

       echo "<table border=1> 
        <tr> 
         <td>appliaction</td> 
         <td>identifier</td> 
         <td>lifecycle</td> 
         <td>useability</td> 
         <td>epochtime</td> 
         <td>appliaction</td> 
         <td>identifier</td> 
         <td>lifecycle</td> 
         <td>useability</td> 
         <td>epochtime</td> 
         <td>Diff epochtime</td> 

        </tr> 

       "; 
       $rowCount = 1; 
       while($row=mysql_fetch_array($run)){ 
        $application = $row['application']; 
        $identifier = $row['identifier']; 
        $lifecycle = $row['lifecycle']; 
        $useability = $row['useability']; 
        $epochtime = $row['epochtime']; 
       ?> 

        <?php 
        if($rowCount%2==1) { 
         echo "<tr>"; 
         $firstEpochTime = $epochtime; 
        } 
        if(strpos($lifecycle, 'Request') !== false) { 
         $applicationRequest = $application; 
         $idRequest = $identifier; 
         $lifecycleRequest = $lifecycle; 
         $useabilityRequest = $useability; 
         $epochtimeRequest = $epochtime; 
        } 
        if(strpos($lifecycle, 'Reply') !== false) { 
         $applicationReply = $application; 
         $idReply = $identifier; 
         $lifecycleReply = $lifecycle; 
         $useabilityReply = $useability; 
         $epochtimeReply = $epochtime; 
        } 
        ?> 

        <?php 
        if($rowCount%2==0) { 
         $lastEpochTime = $epochtime;?> 

         <td><?php echo $applicationRequest;?></td> 
         <td><?php echo $idRequest;?></td> 
         <td><?php echo $lifecycleRequest;?></td> 
         <td><?php echo $useabilityRequest;?></td> 
         <td><?php echo $epochtimeRequest;?></td> 

         <td><?php echo $applicationReply;?></td> 
         <td><?php echo $idReply;?></td> 
         <td><?php echo $lifecycleReply;?></td> 
         <td><?php echo $useabilityReply;?></td> 
         <td><?php echo $epochtimeReply;?></td> 

         <td><?php echo $epochtimeReply-$epochtimeRequest;?></td> 
        <?php echo "</tr>"; 
        } 
        $rowCount = $rowCount + 1; 
        ?> 



     <?php } 
     echo "</table>"; 
     ?> 

     </div> 





    </body> 
</html> 
+0

Üzgünüm ama bu bana yardımcı olamaz. :( – user3514283

+0

Ben thedtabase ve beklenen php ekranı için anlık görüntü ile birlikte soruya daha fazla discription ekledik. Daha fazla bilgi gerekiyorsa lütfen bana bildirin – user3514283

+0

Çalışma kodu eklendi Umut yardımcı olur ... :) – user3514283