我正在寻找一个过滤系统,我的数据库记录。我可以加载记录,但我希望使用一个JQuery移动下拉栏过滤多个关键字的记录。然而,我不知道如何把这一切结合在一起。
下面是JQuery移动下拉选项的代码:
<label for="select-h-6a">Genre</label>
<select name="select-h-6a" id="select-h-6a">
<option value="#">Rock</option>
<option value="#">Pop</option>
<option value="#">Dance</option>
</select>
<label for="select-h-6b">Role</label>
<select name="select-h-6b" id="select-h-6b">
<option value="#">Singer</option>
<option value="#">Drummer</option>
<option value="#">Guitar</option>
</select>
<label for="select-h-6c">Members</label>
<select name="select-h-6c" id="select-h-6c">
<option value="#">1</option>
<option value="#">2</option>
<option value="#">3</option>
</select>
</fieldset>
</form>
下面是我的代码,上面有帖子标题和帖子内容,我可以添加更多的内容来发布,但现在只有那些选项:
$posts = getAllPosts();
<div id="searchpost">
<div class="ui-bar ui-bar-a">
<div id="postTitle">
<?php echo $posts[$p]["post_title"];?></div>
</div>
<div class="ui-body ui-body-a">
<div id="postContent">
<?php echo $posts[$p]["post_content"];}?></div>
</div>
</div>
和职能:
function getAllPosts() {
require "config.php";
$posts = $c->query ( "SELECT * FROM posts" );
if ( $posts->num_rows > 0 ) {
while( $row = $posts->fetch_assoc() ) {
$postData[] = array( "user_id" => $row[ "user_id" ], "post_title" => $row[ "post_title" ], "post_content" => $row[ "post_content" ] );
}
} else {
return "No Data";
}
return $postData;
}
但是,正如您所看到的,它具体地调用了数据库中的内容。如何使我在下拉菜单中选择的内容被显示,而不是显示细节。
这可以添加到多个选定的选项,如选择摇滚,歌手和2个成员,只显示所有三个在其中的记录。我想,如果我不想要选项2中的特定内容,我可以有一个所有选项,搜索该类别中的所有内容。
因此,我需要帮助:-编写代码来搜索我的数据库记录,并显示在JQuery移动下拉栏中选择的所有选项。
我希望你能理解我需要什么帮助。
编辑:
我的数据库:图像
连接:(config.php)
<?php
$c = mysqli_connect( "localhost", "user", "pass", "database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
发布于 2017-01-19 07:42:23
我假设这个问题是关于如何基于提交的表单数据构建SQL查询。如果您使用PDO扩展,它可能会更安全(而且通常更容易)。php.net会帮你的。
在迁移到PDO (强烈推荐)之后,您的查询将大致如下所示。
$sql = ‘select * from posts
where genre=:genre
and role=:role
and members=:members’;
$sth = $dbh->prepare($sql);
$sth->execute(
array(‘:genre’ => $_GET[‘genre’],
‘:role’ => $_GET[‘role’],
‘:members’=> $_GET[‘members’])
);
$result = $sth->fetchAll(); // this should be enough to echo a result
https://stackoverflow.com/questions/41732123
复制相似问题