计算不同行的多个列的值?

时间:2018-02-03 15:20:31

标签: php foreach

我的逻辑有问题。我有一张桌子,里面有10个。那10个col包含8个不同的问题。每个问题都回答为是和否,每个ROW问题的回答都不同(请查看下表)。我想一次计算一个特定行的标记 但由于某些原因,当我获取值时,我有不同的行标题和描述,但每行的标记相同(请参阅下面的输出)。我每行得到4.5分。我想要的只是不同行的单独标记。

MY TABLE STRUCTURE THE OUTPUT

YES的值为1 NO的值为0。 我将这些值与我的标记方案相乘。

我在这段代码的帮助下计算了这个值:

<!DOCTYPE html>
<?php
include 'common.php';
$command = "SELECT Title, Description, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8  FROM sachjot";
// prepare and executing
$stmt = $dbh->prepare($command);
$result = $stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); // get all result using this

$p; // variable to store all the values of different questions per row

foreach($results as $data){
  $data['Question1'];
  $data['Question2'];
  $data['Question3'];
  $data['Question4'];
  $data['Question5'];
  $data['Question6'];
  $data['Question7'];
  $data['Question8'];


  if ($data['Question1'] == "YES"){
        $p +=  1 * 1;        // 1 is the marking scheme marks
  }else{
    $p = 0 * 1;
  }

  if ($data['Question2'] == "YES"){
    $p +=  + 1 * 0.5;       // 0.5 is the marking scheme marks
  }else{
    $p += 0 * 0.5;
  }

  if($data['Question3'] == "YES"){
    $p += 1 * 2;           // 2 is the marking scheme marks
  }else{
    $p += 0 *2;
  }

  if($data['Question4'] == "YES"){
    $p += 1*1;
  }else{
    $p += 0 * 1;
  }

  if($data['Question5'] == "YES"){
    $p += 1 *1.5;
  }else{
    $p += 0 * 1.5;
  }

  if($data['Question6'] == "YES"){
    $p += 1 * 1;
  }else{
    $p += 0 * 1;
  }

  if($data['Question7'] == "YES"){
    $p += 1 * 1;
  }else{
    $p += 0 *1;
  }

  if($data['Question8'] === "YES"){
    $p += 1 * 2;
  }else{
    $p += 0*2;

}
}
 ?>

借助此代码获取它们:

              <?php
        foreach($results as $row){
          // echo "<tr><td>".$row["rank"]."</td>";
          echo "<tr><td>".$row['Title']."</td>";
          echo "<td>".$p."</td>";
          echo "<td>".$row['Description']."</td></tr>";
         }
        ?>

1 个答案:

答案 0 :(得分:1)

试试这个:

364 /*                                                                                                                                                                                           
365  * Build a proper pagetable for the kernel mappings.  Up until this
366  * point, we've been running on some set of pagetables constructed by
367  * the boot process.
368  *
369  * If we're booting on native hardware, this will be a pagetable
370  * constructed in arch/x86/kernel/head_32.S.  The root of the
371  * pagetable will be swapper_pg_dir.
372  *
373  * If we're booting paravirtualized under a hypervisor, then there are
374  * more options: we may already be running PAE, and the pagetable may
375  * or may not be based in swapper_pg_dir.  In any case,
376  * paravirt_pagetable_setup_start() will set up swapper_pg_dir
377  * appropriately for the rest of the initialization to work.
378  *
379  * In general, pagetable_init() assumes that the pagetable may already
380  * be partially populated, and so it avoids stomping on any existing
381  * mappings.
382  */
383 static void __init pagetable_init(void)
384 {