tags:

views:

45

answers:

1

Hello, I am trying to get an id value of a link with jquery then send that id to a php script (in this case sending it to a php sql query).

I have a link like this on the main page:

<a href="#" id="category1">Category One</a>

when this link is clicked, I would like jquery to grab the id value ('category1') and place it in a seperate php file that holds my db queries.

in other words the id value would be inserted into the query below once the link is clicked so I don't have to manually enter in the category part of the query:

SELECT * FROM maindb WHERE category="category1"

Any help on this would be great, thanks.

+1  A: 
<a class='foo' id='category1'>Category One</a>
<a class='foo' id='category2'>Category Two</a>
<a class='foo' id='category3'>Category Three</a>

<script>
$(document).ready(function() {
    $('.foo').click(function() {
        // You might do:
        window.location='somefile.php?id=' + this.id;
        // or pass it as an argument to 
        $.getJSON('somefile', {id: this.id}, function(result) { alert('Success') });
    });
});
</script>
MightyE
If I use the pass argument, is there a way I can get the id in my PHP file? How would I grab it in the PHP file?
SOFuser
It shows up in $_GET['id']
MightyE