dqq3623 2014-09-22 09:03
浏览 39
已采纳

使用下拉列表修改php变量以生成不同数量的SQL结果

I have a form that queries a SQL database with a stored procedure and generates TOP 100 results. I would like to put a dropdown box next to the search button to choose how many results to display.

I imagine doing this by running a different stored procedure for each amount (i.e. TOP 100, TOP 200, TOP 300 etc.) so I want to change the $query variable being executed by the 'Search' button to run each of these stored procs.

Can PHP do this or do I need javascript/AJAX?

Example of my code:

echo '<input class="btn btn-primary btn-lg active" type="submit" name="search" value="Search">    <br><br>';

$query = "EXEC dbo.sp_HeaderSearch100";

Any help would be greatly appreciated! Thanks

  • 写回答

1条回答 默认 最新

  • donglian5309 2014-09-22 09:11
    关注

    You can do this with the basic POST.

    Your markup would look like:

    <input type="text" name="amount" /> <!-- or select/option with the same name, etc. -->
    <input type="submit" class="..." name="search" />
    

    Then your backend would process it simply as:

    // Use an array of available "top" procs
    // Otherwise use a default (e.g. 100)
    $top = in_array($_POST['amount'], array(100, 200, 300)) ? $_POST['amount'] : 100;
    $query = "EXEC dbo.sp_HeaderSearch$top"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序