doucong3048 2014-11-22 13:42
浏览 6
已采纳

使用<href>更改查询[关闭]

I have set a default query

$query = "SELECT Image, ISBN, Name, Vol, Release_date, publisher, price  FROM products p order by Name,vol";
echo "<a href = ???>Date</a>";

so that the query can be changed in sorting by date after clicking? Thank you!

  • 写回答

1条回答 默认 最新

  • duan47676379 2014-11-22 14:03
    关注

    The sorting/ordering parameter is order by Name,vol at the end of the query. So you might make it as a variable depending on whether the GET['date'] is present from href.

    <?php
    $sortvar = isset($_GET['date']) ? 'order by '. $_GET['date'] : 'order by Name,vol'; 
    if (isset($_GET['ndsn']) &&  isset($_GET['date']) ) 
        $sortvar =  'order by '. $_GET['date'] . ',' . $_GET['ndsn'];     
    $query = "SELECT Image, ISBN, Name, Vol, Release_date, publisher, price  FROM products p " . $sortvar;
    
    echo "<a href = '?date=Date'>Date</a><br>";
    echo "<a href = '?date=Date&ndsn=NDSN'>Date & NDSN</a><br>";
    echo $query;
    

    IMPORTANT

    you MUST escape GET parameters or parametrize your result query when adding GET parameters into it, cause of SQL-injections possibility.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作