duandaodao6951 2016-01-20 08:40
浏览 27
已采纳

通过组合2个无序列表在php中搜索

I have an unordered list which somebody can search for images which belongs in current category. i have this code in a while loop:

<li><a class="ct" href="account.php?view_templates&category=<?php echo $category['id']; ?>"><?php echo $category['name']; ?></a></li>

Also i have an unordered list which somebody can search for images which belongs in a current size.I have used jquery to get the li value and send it via ajax to php file to give me the results.

<li value="728x90"><a href="#">728x90</a></li>

I get the results using this code to my php file:

if(isset($_POST['size'])){
  $size = $_POST['size'];
  $gs = $db->query("SELECT * FROM images WHERE size = '$size'");
  while($images = $gs->fetch(PDO::FETCH_ASSOC)){
    //I store the images here
  }
}

The problem is that when somebody has selected a category and after that he trying to select a size, then as result i have only the size but no the current category. The wished result is to search the sizes but in the specific selected category..not to all categories.. how can i do that? Thanks..

  • 写回答

2条回答 默认 最新

  • dongtaijue1578 2016-01-20 09:38
    关注

    Database : postgresql

    Try to make your query in parts.

    $size = $_POST['size'];
    $category = $_POST['category'];
    
    if(isset($size)){
      $size = "AND size = $size";
    }
    if(isset($category)){
      $category = "AND category = $category";
    }
    
    $query = "SELECT * FROM images WHERE true $size $category";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度