使用AJAX php过滤

时间:2016-05-20 10:27:54

标签: php ajax

我有以下php文件过滤器:

<?php
include 'config.php';
$output='';
$category_filter = $_POST["category_filter"];
$query="SELECT * FROM products WHERE product_category like '".$category_filter."%'";
// $query="SELECT * FROM product WHERE category like 'asd%'";
$result = mysqli_query($conn,$query);
$output .= '
    <div class="responsive_table">
        <table class="table table-bordered">
            <tr>
                 <th width="20%">Code</th>
                 <th width="10%">Name</th>
                 <th width="20%">Description</th>
                 <th width="10%">Price</th>
                 <th width="20%">Category</th>

            </tr>';

foreach ($result as $row) {
    $output .= '
        <tr>
            <td>'.$row["product_code"].'</td>
            <td class="product_name">'.$row["product_name"].'</td>
            <td class="product_desc">'.$row["product_desc"].'</td>
            <td class="product_price">'.$row["product_price"].'</td>
            <td class="product_category">'.$row["product_category"].'</td>
            <td><button type="button" name="delete_btn" id="'.$row["product_id"].'" class="delete_btn btn btn-xs btn-danger btn_delete">x</button>

            </td>
        </tr>
        ';
}
$output .= '
       <tr>
            <td id="product_code" contenteditable></td>
            <td id="product_name" contenteditable></td>
            <td id="product_desc" contenteditable></td>
            <td id="product_price" contenteditable></td>
            <td id="product_category" contenteditable></td>
            <td><button type="button" name="add_btn" id="add_btn" class="btn btn-xs btn-success">+</button></td>
       </tr>
  ';
$output .= '</table>
</div>';
echo $output;
?>

我不知道如何将它放在我的应用程序中工作。我的主文件,其中列出了我的数据库中的所有产品:

<?php
session_start();
include_once("config.php");


//current URL of the Page. cart_update.php redirects back to this URL
 $current_url =      urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
 ?>
 <!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Shopping Cart</title>
 <link href="style/style.css" rel="stylesheet" type="text/css">
 </head>
 <body>

 <h1 align="center">Products </h1> 

 <?php 
 $results = $mysqli->query("SELECT product_code, product_name, product_desc, product_category, price FROM products ORDER BY id ASC");
 if($results){ 
 $products_item = '<ul class="products">';
 //fetch results set as object and output HTML
 while($obj = $results->fetch_object())
 {
 $products_item .= <<<EOT

<form method="post" action="cart_update.php">
<table>
<tr>
<td> Name: {$obj->product_name}</td>
<td>Description: {$obj->product_desc}</td>
<td> Price: {$currency}{$obj->price} </td>
<td> Category: {$obj->product_category}
</td>
<td>
    <span>Quantity: </span>
    <input type="text" size="2" maxlength="2" name="product_qty" value="1" />
</td>
<td>
<div align="center"><button type="submit" class="add_to_cart">Add</button></div></td>
<input type="hidden" name="product_code" value="{$obj->product_code}" />
<input type="hidden" name="type" value="add" />
<input type="hidden" name="return_url" value="{$current_url}" />

</div></div>
</form>
</table>
EOT;
}
$products_item .= '</ul>';
echo $products_item;
}
?>    

我知道这是一个愚蠢的问题,但我真的不知道如何将它集成到我的项目中去工作。有什么建议吗?

0 个答案:

没有答案