0

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!

4

2 回答 2

2

是的,就像使用逗号一样简单

$.get("test.php", { name: "John", time: "2pm" } );

从 JQuery 站点复制和粘贴。

参考: http ://api.jquery.com/jQuery.get/#entry-examples

所以你所做的是正确的,检查你的 () 标签,因为你错过了一个

于 2012-11-11T20:11:51.347 回答
2

是的,这是可能的。您在第二个示例中做得恰到好处,希望您)在代码中忘记了一个$('input[name=site]')

function search() {     
 $.get("./scripts/search.php", {"_input" : $('input[name=input]').val(), "_site" :     $('input[name=site]').val()},
    function(returned_data) {
                $("#output").html(returned_data);
    }
);
}
于 2012-11-11T20:12:49.717 回答