I am making a comics website… it will have two sub sites: Comics and Artwork.
When someone clicks on a specific sub site, a “site” parameter will be passed in (comics or artwork) which specifies from which table (comics or artwork) images should be queried.
That all works… except I am trying to add this extra parameter to this search function which currently only accepts the input string, but doesn’t know which table to search.
So, I have a search function that accepts input from an input box:
<span class="search"><input type="text" onkeyup="search(this.value)" name="input" value="" /></span>
JQuery:
function search() {
$.get("./scripts/search.php", {"_input" : $('input[name=input]').val()},
function(returned_data) {
$("#output").html(returned_data);
}
);
}
PHP search script… gets search string input
$input = (isset($_GET['_input']) ? ($_GET['_input']) : 0);
But I’d also like to pass in a “_site” parameter that specifies from which subsite on my website images should be returned from:
function search() {
$.get("./scripts/search.php", {"_input" : $('input[name=input]').val(), "_site" : $('input[name=site]'.val()},
function(returned_data) {
$("#output").html(returned_data);
}
);
}
So the PHP search script would get search string, but also know which site it’s on:
$input = (isset($_GET['_input']) ? ($_GET['_input']) : 0);
$site = (isset($_GET['_site']) ? ($_GET['_site']) : null);
Is it possible to send in multiple parameters through the JQuery? Is that even the right way to do it?
————EDIT
This is how the “site” search param is affecting the search query
$site = (isset($_GET['_site']) ? ($_GET['_site']) : null);
echo "SEARCH SITE = " . $site;
if($site == "artwork") {
$id = "artid";
$title = "arttitle";
$path = "artpath";
$thumb = "artthumb";
$catid = "artcatidFK";
$table = "artwork";
$thumbpath = "./images/Artwork/ArtThumbnails/";
}
else {
$id = "imgid";
$title = "imgtitle";
$path = "imgpath";
$thumb = "imgthumb";
$catid = "imgcatidFK";
$table = "comics";
$thumbpath = "./images/Comics/ComicThumbnails/";
}
$imgpaths = $mysqli->query("SELECT $id, $title, $path, $thumb, $catid FROM $table");
mysqli_close($mysqli);
Thanks!
Yes, this is possible. You are doing it just right in your 2nd example, expect that you forgot one
)in your code$('input[name=site]')