【问题标题】:Show records in the table with if - PHP使用 if - PHP 在表中显示记录
【发布时间】:2018-10-20 08:03:46
【问题描述】:

我有一个植物表和一个客户活动表,我只想显示与客户活动表无关的植物。

通过这个 if 循环,我想得到一个解决方案,比如如果它是真的不显示关联的植物,如果它是假的则显示不关联的植物

有可能吗?

   <?php

    session_start();

    include 'connessione.php';


    $var = true;
    $var = 1;

    $query = mysqli_query($connessione, "

    SELECT *

    FROM store_locator

    INNER JOIN campagne_cliente

    ON store_locator.id = campagne_cliente.impianto_id_campagna");


    if (!$query)

      {
         die('Error: ' . mysqli_error($connessione));
      }

    if($var === true){

        echo "email already exists";

    }else{

        echo "ok";

    }
    ?>

但如果我只有相关的植物而没有免费的植物,我总是可以的。 为什么?

【问题讨论】:

    标签: php mysql inner-join


    【解决方案1】:

    正确:

    <?php
    
    session_start();
    
    include 'connessione.php';
    
    $id = $_SESSION['id'];
    
    $query_string = "SELECT * FROM store_locator WHERE store_locator.id NOT IN (SELECT impianto_id_campagna FROM campagne_cliente);
    ";
    
    $query = mysqli_query($connessione, $query_string);
    
    ?>
    
    
    
    <?php
    
    while($row = mysqli_fetch_assoc($query)){ ?>
    
    <?php echo $row['id'] ;?>
    
    <?php } ?>
    

    【讨论】:

      【解决方案2】:

      不要在这样的查询中使用.... AM Just Try to了解你,你可以根据你的表结构来管理它。

       SELECT * FROM `plant_table` not in (select customer_campaign.plant_id from customer_campaign);
      

      希望这会对您有所帮助。 谢谢

      我得到了这个结果:

      Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not in (select campagne_cliente.impianto_id_campagna from campagne_cliente)' at line 2
      

      这是一个查询:

       SELECT * FROM `store_locator` 
       not in 
       (select campagne_cliente.impianto_id_campagna
       from campagne_cliente);
      

      【讨论】:

      • SELECT * FROM store_locator not in INNER JOIN campagne_cliente ON store_locator.id = campagne_cliente.impianto_id_campagna
      猜你喜欢
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      • 2016-02-19
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多