dqjcb132285 2016-09-27 10:13
浏览 34

如何进行动态选择?

I have this sql query:

$sql1="SELECT articoli.sconto_st as promozione,  marche.ID,marche.marca, categorie.ID,articoli.marche_ID,articoli.categorie_ID,categorie.categoria
FROM articoli,categorie, marche
AND articoli.categorie_ID=categorie.ID
AND articoli.marche_ID=marche.ID
AND marca='$marcavalue'
AND categoria='$categoriavalue'
  ";
$result1=mysqli_query($con,$sql1);

I want to output some of the datas:

<?php
    while($row1=mysqli_fetch_array($result1)) {
        echo "<tr>";
        echo '<td class="tab1"><b>'. $row1["marca"]  . '<b> '. $row1["promozione"].'</b>  </br></td>'; //scala
        echo "</tr>";

I want to select all of the data like in the query above but the promozione to output only if it is 1.So the other data to be selcted and outputted but the promozione to be outputed only if it is 1. When it is different from 1 to output just marca. Is there a way to do this?

</div>
  • 写回答

1条回答 默认 最新

  • doude5860 2016-09-27 10:19
    关注
    <?php
    while($row1=mysqli_fetch_array($result1)) {
        $promozione= ($row1['promozione'] == 1) ?1 :"";
        echo "<tr>";
        echo '<td class="tab1"><b>'. $row1["marca"]  . '<b> '. $promozione.'</b>  </br></td>'; //scala
        echo "</tr>";
    

    This line, which I added: $promosione = ($row1['promozione'] == 1) ?1 :""; is short hand for:

    if ($row1['promozione'] == 1){
        $promozione= "1";
    }else{
        $promozione= "";
    }
    

    I hope this solves your question.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题