简体   繁体   English

使用jQuery运行PHP并使用变量

[英]Run PHP with jQuery and use variable

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. 我有一个ID,NAME,LINK和CATEGORY的表。 I want that if you click the DIV with the attribute "ford", you select all from the table where category is ford. 我希望如果您单击具有“ ford”属性的DIV,则从表中的“福特”类别中全选。 This is my code: 这是我的代码:

jQuery jQuery的

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

and the SQL: 和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? 我知道PHP是一种服务器端语言,而JS不是,并且JS是事件驱动的,而且是全部,但这是最简单的方法呢? Do I need to use forms and stuff? 我需要使用表格和东西吗?

Sorry for bad english! 对不起,英语不好!

使用$ .ajax或$ .post调用,并将变量作为post(或get)变量传递。

U can use AJAX() to get HTTP communication with PHP in backend. 您可以使用AJAX()在后端与PHP进行HTTP通信。 see more in [link] http://api.jquery.com/jQuery.ajax/ 在[link] http://api.jquery.com/jQuery.ajax/中查看更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM