将Dropdown查询添加到现有循环?

时间:2014-05-31 20:52:22

标签: php drop-down-menu

我正在使用while循环和分页来过滤记录。我想在循环中添加一个下拉列表,以便访问者更容易浏览记录。我已经调试并且没有错误但是fetch数组不起作用,我没有得到任何数据。连接是表单和图像数据配对所必需的,我存储并检索上传到文件夹中的图像的路径。

<?php
session_start();
include "connect.php";
error_reporting(E_ERROR);
//select records from two tables and loop through results
$result = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id ORDER BY tcgcomics.id");
$count = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
$tcgname[]= $row['name'];
$tcgintelligence[]= $row['intelligence'];
$tcgstrength[]= $row['strength'];
$tcgspeed[]= $row['speed'];
$tcgenergy[]= $row['energy'];
$tcgfighting[]= $row['fighting']; 
$tcggoogle[]= $row['google']; 
$tcgbiography[]= $row['biography'];
$img_paths[] = $row["path"];

//通过dropown过滤记录

if(isset($_POST['Filter'])){
if($_POST['value'] == 'Apocalypse'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Apocalypse' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Black Adam'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Black Adam' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Darkseid'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Darksied' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Doomsday'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Doomsday' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Gladiator'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Gladiator' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Mongul'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Mongul' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Hulk'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Hulk' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Hyperion') {$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Hyperion' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Thanos'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Thanos' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Ultron'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Ultron' ORDER BY tcgcomics.id;");}
else{

//pagination
if(empty($_GET['page'])){
    $i = $count - 1;
$current = $count;
}else{
$i = $_GET['page'];
$current = $i;
$i = $i - 1;
}
if($i == 0 && $count == 1){
    $prevlink = "";
    $next = $current + 1;
    $nextlink = "";
}elseif($i == 0 && $count > 1){
    $prevlink = "";
    $next = $current + 1;
    $nextlink = "<a href='?page=$next'>Next</a>";
}elseif($current > 0 && $current < $count){
    $prev = $current - 1;
    $next = $current + 1;
    $prevlink = "<a href='?page=$prev'>Previous</a>";
    $nextlink = "<a href='?page=$next'>Next</a>"; 
}elseif($current == $count){
    $prev = $current - 1;
    $prevlink = "<a href='?page=$prev'>Previous</a>";
    $nextlink = "";
}
}
}
}
?>

1 个答案:

答案 0 :(得分:0)

检查第6行:最后需要一个分号。

此外,您在所有查询语句中都有不需要的分号。在mysql_query中你不需要它们。

e.g。改变mysql_query(“SELECT * from tcgcomics WHERE name ='Apocalypse';”); to mysql_query(“SELECT * from tcgcomics WHERE name ='Apocalypse'”);