我正在建立一個漫畫網站,它有兩個子網站:漫畫和藝術品。漫畫和藝術品存儲在兩張獨立的桌子上。選擇查詢使用jquery單選按鈕的多個表格
我有一個搜索功能,允許用戶搜索圖像。
我想給他們一個選項來選擇只搜索漫畫,只有藝術品,或兩者兼而有之。
我有以下的JavaScript,我相信應該是工作:
<script type="text/javascript">
function search(searchString) {
var site = $("#site").val();
$.get("./scripts/search.php", {_input : searchString, _site : site},
function(returned_data) {
$("#output").html(returned_data);
}
);
}
function searchChoice(choice) {
$.get("./scripts/search.php", {_choice : choice}
);
}
</script>
而下面的HTML:
<!--Search filtering for comics, artwork, or both-->
<span class="search"><b>Search for: </b> </span>
<div class="btn-group" data-toggle="buttons-radio">
<span class="search">
<button type="button" class="btn" id="comics" onclick="searchChoice(this.id)">Comics</button>
<button type="button" class="btn" id="artwork" onclick="searchChoice(this.id)">Artwork</button>
<button type="button" class="btn" id="all" onclick="searchChoice(this.id)">All</button>
</span>
</div>
<br/>
<br/>
<!--Search functionality-->
<span class="search">
<input type="text" onkeyup="search(this.value)" name="input" value="" />
<input id="site" type="hidden" value="<?php echo $site; ?>">
</span>
<br />
<span id="output"><span class="sidebarimages"> </span></span>
我的問題是在這裏與PHP查詢兩個表中的:
我正在JOIN正確嗎?
$input = (isset($_GET['_input']) ? ($_GET['_input']) : 0);
$choice = (isset($_GET['_choice']) ? ($_GET['_choice']) : "all");
$site = (isset($_GET['site']) ? ($_GET['site']) : null);
if ($choice == "artwork") {
$sql = "SELECT id, title, thumb FROM artwork";
$thumbpath = "./images/Artwork/ArtThumbnails/";
}
else if ($choice == "comics") {
$sql = "SELECT id, title, thumb FROM comics";
$thumbpath = "./images/Comics/ComicThumbnails/";
}
else {
$sql = "SELECT id, title, thumb FROM comics
UNION
SELECT id, title, thumb FROM artwork";
$thumbpath = "./images/AllThumbnails/";
}
$imgpaths = $mysqli->query($sql);
mysqli_close($mysqli);
謝謝!
如果確實要加入,您必須指定要加入的字段。我建議只運行2個選擇語句。我也沒有看到任何'where'條款,這意味着你會返回一切。 – Archer