doulian7252 2014-03-06 11:54
浏览 44
已采纳

获取MySQL数据单击时WHERE列等于HTML链接

Don't quite know how to work this one, any help would be much appreciated. So I'm trying to display the products which match the column of the link which have been clicked. I have succeeded in doing it for the search function when I click a button (Search). Now I'm trying to implement similar method for when a link is pressed.

    $sql = "SELECT * FROM products ";
    if(isset($_POST['Submit'])){
        if(empty($_POST['Search'])){
            $error = true;
        }else{
        $searchq = mysql_real_escape_string($_POST['Search']);
        $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
        $sql .= "WHERE type LIKE '%$searchq%' or name LIKE '%$searchq%'";       
    } 
} $query = mysql_query($sql) or die(mysql_error());

The links are something like this, so when a user has clicked the link, it displays data according to name="" in link which matches the column type in the table products.

<ul>
            <li name="Books" class="menu-781"><a href="#">Books</a></li>
            <li name="Perfume" class="menu-780"><a href="#">Perfume</a></li>
            <li name="Gifts" class="menu-789"><a href="#">Gifts</a></li>
            <li name="Stationery" class="menu-778 last""><a href="#">Stationery</a></li>
        </ul>

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dpo69086 2014-03-06 11:59
    关注

    try it this code

    <ul>   
            <li name="Books" class="menu-781"><a href="search.php?q=Books">Books</a></li>
            <li name="Perfume" class="menu-780"><a href="search.php?q=Perfume">Perfume</a></li>
            <li name="Gifts" class="menu-789"><a href="search.php?q=Gifts">Gifts</a></li>
            <li name="Stationery" class="menu-778 last""><a href="search.php?q=Stationery">Stationery</a></li>
        </ul>
    

    and in your php

    $sql = "SELECT * FROM products ";
        if(isset($_GET['q'])){
            if(empty($_GET['q'])){
                $error = true;
            }else{
                $searchq = mysql_real_escape_string($_GET['q']);
                $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
                $sql .= "WHERE type LIKE '%$searchq%' or name LIKE '%$searchq%'";       
            } 
        } 
    $query = mysql_query($sql) or die(mysql_error());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!