如何从Jquery中用作php Query的变量

时间:2022-08-27 17:42:21

I have this code below which display the item that has been clicked using Jquery

我在下面的代码中显示了使用Jquery单击的项目

<html>
<head>

    <?php include('config/js.php');?>

</head>
<body>
                                    <div id="target">
                                        <h4>Hydraulics</h4>
                                        <ul>
                                            <li><a href="#">Bikes</a></li>
                                            <li><a href="#">Utes</a></li>
                                            <li><a href="#">cars</a></li>
                                            <li><a href="#">Trucks</a></li>

                                        </ul>
                                    </div>
<body>
    <script>
       $('#target li').click(function() {
            var text = $(this).text();
            alert('Text is ' + text);
        });
    </script>

 </html>

Is there a way I can use this output as a variable for php query something like below so that I can use '$var' instead of 'Trucks';

有没有办法我可以使用此输出作为php查询的变量,如下所示,以便我可以使用'$ var'而不是'Trucks';

<?php
             $q = "SELECT subgroup FROM jqm_categories WHERE name = 'Trucks' ";
             $r = mysqli_query($dbc, $q);

             While($list = mysqli_fetch_assoc($r)) {?>

         <a href="#" class="catag"><?php echo $list['subgroup'].'<br/>';?></a>

                <?php } ?>

1 个解决方案

#1


0  

In the javascript put

在javascript中放

$.get("http://example.com/foo.php?name=" + text);

instead of the alert and in the php use:

而不是警告和在PHP使用:

mysql_real_escape_string($_GET['name'])

instead of Trucks.

而不是卡车。

#1


0  

In the javascript put

在javascript中放

$.get("http://example.com/foo.php?name=" + text);

instead of the alert and in the php use:

而不是警告和在PHP使用:

mysql_real_escape_string($_GET['name'])

instead of Trucks.

而不是卡车。