Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Using PHP with MySQL Querying the Database with PHP Querying the Database

Where do you put the PHP if a jQuery event calls the connection to MySQL on a click() event?

Can anyone give me some examples of how to make it so if someone clicks on a DIV element that a foreach loop runs which connects to a MySQL database and then runs a query with a foreach loop. I would appreciate if you would do it in the PDO format with the -> and/or with mysqli (with the i) since that is what I see around the most.

Do you put the PHP code in the .js folder on a file that ends in .js OR in the index.php folder. I am so confused how to mix PHP with jQuery and where to put it when you are running a query.

1 Answer

Gabriel Furet
PLUS
Gabriel Furet
Courses Plus Student 9,189 Points

I think What you want to know is AJAX, download and try to understand this example http://www.91weblessons.com/php-ajax-login-validation-tutorial/ is quite easy and common task to learn using AJAX. Your request wasn't so clear to me, I hope this would help you.