dougaxing8673 2010-07-27 18:45
浏览 33
已采纳

如何使用jQuery将链接ID发送到sql查询?

I am trying to send link id's to a sql query in order to filter data.

When I click a link like the ones below, I want to send the id of the link to the sql query as shown below:

Example: Links (clicked):

<p>Fitler Results</p>
<a href="#" class="category" id="marketing">Marketing</a>

<a href="#" class="category" id="automotive">Automotive</a>

(not clicked):

<a href="#" class="category" id="sports">Sports</a>

sql query - I hardcoded the id's in, but I want it to do that automatically when someone clicks a link, in this case marketing and automotive, I want the id's to insert automatically using jquery but have no idea how to properly do it:

$query1 = "SELECT * FROM explore WHERE category IN ('marketing', 'automotive',) ORDER BY category LIMIT $start, $limit";
  • 写回答

2条回答 默认 最新

  • douzhuan0309 2010-07-27 18:54
    关注

    just do a jquery ajax post with a return false, and capture the result.

    $('a').click(function(){
      $.post("querypage.php", { id: "$(this).attr('id')"},
         function(data){
           dosomethingwithdata(data);
      });
     //return false to insure the page doesn't refresh
     return false;
    });
    

    Then in your php page (=querypage.php) do:

    $query1 = "SELECT * FROM explore WHERE".$_POST["id"]."IN ('marketing', 'automotive',) ORDER BY category LIMIT $start, $limit";
    

    offcourse you now have to execute the query and return the result you want.

    I hope this helps, comment me if there is any problem

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了