0

I'm making a website where you can find manuals of different brands of cars. I have a table with ID, NAME, LINK, and CATEGORY. I want that if you click the DIV with the attribute "ford", you select all from the table where category is ford. This is my code:

jQuery

$('div').click(function(){
    var cat = $(this).attr('category');
});

and the SQL:

$connect = new PDO('mysql:host=localhost;dbname=manuals', 'root','');
$cmd = $connect -> query("SELECT * FROM `manuals` WHERE `category`='ford'");
$resultado = $cmd->fetchAll(PDO::FETCH_ASSOC);

I know that PHP is a server side language and JS not, and JS is event driven, and all the story, but what is the easiest way to achieve this? Do I need to use forms and stuff?

Sorry for bad english!

2 Answers 2

1

Use an $.ajax or $.post call and pass in the variable as a post (or get) variable.

Sign up to request clarification or add additional context in comments.

1 Comment

So, execute the ajax function when clicking the div, right? will try this... thanks
1

U can use AJAX() to get HTTP communication with PHP in backend. see more in [link]http://api.jquery.com/jQuery.ajax/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.