mysql简单查询+如果

时间:2016-09-23 14:24:38

标签: php mysql doctrine

好像我无法进行简单的查询。

我想要实现的是所有具有'best2'值'1'的结果,因此div将仅附加到那些结果。

现在,div'badge-best2div'附加到所有产品上。

我不知道我错过了什么。

<?php $show = true; ?>
        <?php

        $roman  = Doctrine_Query::create()->from("Product")
                                  ->where("status = 1")
                                  ->andWhere("site_id = ? ", SITE_ID)
                                  ->andWhere("best2 = 1")
                                  ->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);

         ?>
        <?php if ($product->getIsTop()  && !isset($hide_badge_top)): $show = false;?>
            <div class="badge-top"></div>
        <?php endif; ?>
        <?php if ($roman['best2']){ 
            $show = false;      ?>
            <div class="badge-best2div"></div>
        <?php } ?>

    <?php if ($product->getIsBestBuy() && !isset($hide_badge_bestbuy) && $show): ?>
            <div class="badge-bestbuy"></div>
        <?php endif ; ?> 

1 个答案:

答案 0 :(得分:0)

使用

使其工作
if (!$_REQUEST['search']) {

  $sql = "SELECT * FROM users_table ORDER BY lname ASC";

  $retvalues = mysqli_query($conn, $sql);

  $counter = 1;

  while ($row = mysqli_fetch_array($retvalues, MYSQL_ASSOC)) {

    $lname = capword($row['lname']);
    $fname = capword($row['fname']);

    if ($row['admin'] != 1) {
      $stringAdmin = "No";
      $admincolor = "<td>";

    } else {
      $stringAdmin = "Yes";
      $admincolor = "<td style='color:red;'>";
    }
    echo "<tr>";
    echo "<td>".$counter.".</td>";
    echo "<td>".$lname." , ".$fname."</td>";
    echo "<td>".$row['email']."</td>";
    echo "<td>".$row['password']."</td>";
    echo $admincolor.$stringAdmin."</td>";
    echo "<td><input type='checkbox' name='user[]' value='{$row['id']}'></td>";
    echo "<td><input type='submit' name='edit' value='edit'></td>";
    echo "</tr>";

    $counter++;
  }
}