dsm0688 2015-07-13 20:01
浏览 14

使用选项框过滤数据

I have an option box that filters the data to be displayed on the page. My data table has information that pertains to a cycle. $row_Recordset2 is just a way for me to view the unique cycles in my table (e.g. Spring, Fall, Winter, Spring) and is the filter in the option box.

SELECT DISTINCT gpa.`Cycle'
FROM gpa
ORDER BY gpa.ID DESC

So my option box would give me my Cycle and only show that data.

<select name="selCycle" id="selCycle" onchange="formFilter.submit()">
<option value="%">all cycles</option>
<?php
do {  
?>
<option value="<?php echo $row_Recordset2['Cycle']?>"<?php if     
($varCycle_Recordset3 == $row_Recordset2['Cycle']) {echo 'selected';} ?>><? 
php echo $row_Recordset2['Cycle']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>

Right now the data is filtered correctly but I always have to display all the data (All Cycles) and then select the Cycle I would like to view.

$varCycle_Recordset3 = "%";
if (isset($_POST['selCycle'])) {
$varCycle_Recordset3 = $_POST['selCycle'];
}
mysql_select_db($database_ss, $ss);
$query_Recordset3 = sprintf("SELECT gpa.ID, gpa.Data,
FROM gpa 
WHERE gpa.Cycle LIKE %s
GetSQLValueString($varCycle_Recordset3, "text")

I would prefer that the latest ID be the default for the page with the user being able to switch Cycles. I'm sure it has to do with the default value set to % or maybe I am using the Where statement incorrectly with gpa.Cycle LIKE %s. I've tried gpa.Cycle = %s instead of LIKE and then no data displays on page load. I of course would like the option box to display the current Cycle and match the Cycle in the option box.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源