使用php

时间:2019-07-13 15:01:47

标签: php jquery ajax phpmyadmin

我是PHP的新手,我发现很难真正理解我的代码中的问题,请任何人帮助我。此处附上了我为此目的创建的三个类,我也试图找出我做错了什么,但是我是PHP编码的新手。任何帮助或建议,将不胜感激。谢谢。

<?php
include_once("../../database/constants.php");
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <!-- Favicon -->
    <link rel="icon" href="../../favicon.ico" type="image/x-icon">

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css">

    <!-- Bootstrap Core Css -->
    <link href="../../assets/plugins/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />

    <!-- Animate.css Css -->
    <link href="../../assets/plugins/animate-css/animate.css" rel="stylesheet" />

    <!-- Font Awesome Css -->
    <link href="../../assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />

    <!-- iCheck Css -->
    <link href="../../assets/plugins/iCheck/skins/flat/_all.css" rel="stylesheet" />

    <!-- Switchery Css -->
    <link href="../../assets/plugins/switchery/dist/switchery.css" rel="stylesheet" />

    <!-- Metis Menu Css -->
    <link href="../../assets/plugins/metisMenu/dist/metisMenu.css" rel="stylesheet" />

    <!-- Jquery Datatables Css -->
    <link href="../../assets/plugins/DataTables/media/css/dataTables.bootstrap.css" rel="stylesheet" />

    <!-- Pace Loader Css -->
    <link href="../../assets/plugins/pace/themes/white/pace-theme-flash.css" rel="stylesheet" />

    <!-- Custom Css -->
    <link href="../../assets/css/style.css" rel="stylesheet" />

    <!-- AdminBSB Themes. You can choose a theme from css/themes instead of get all themes -->
    <link href="../../assets/css/themes/allthemes.css" rel="stylesheet" />

    <!-- Custom JS -->
    <script type="text/javascript" src="../../assets/js/pages/dashboard/main.js"></script>

    <!-- Demo Purpose Only -->
    <link href="../../assets/css/demo/setting-box.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

    <script type="text/javascript">

       window.load=$( document ).ready(function() {

     $.ajax({
                type:'POST',
                url:'http://localhost/Alixia/database/ajax_populate/categoryAjaxData.php',
                success:function(html){
                    $('#select_cat').html(html);

                                      }
                   }); 

                    });  


         $( document ).ready(function() {

        $('#select_cat').on('change',function(){//change function on category to display all brand 
        var categoryID = $(this).val();
        if(categoryID){
            $.ajax({
                type:'POST',
                url:'http://localhost/Alixia/database/ajax_populate/categoryAjaxData.php',
                data:'cid='+categoryID,
                success:function(html){
                    $('#select_brand').html(html);
                    $('#select_product').html('<option value="">Select brand first</option>'); 
                                      }
                   }); 
                      }else{
                           $('#select_brand').html('<option value="">Select category first</option>');
                           $('#select_product').html('<option value="">Select brand first</option>'); 
                           }
    });

    $('#select_brand').on('change',function(){//change brand to display all product
        var brandID = $(this).val();
        if(brandID){
            $.ajax({
                type:'POST',
                url:'ajaxData.php',
                data:'bid='+brandID,
                success:function(html){
                    $('#select_product').html(html);
                                      }
                   }); 
                    }else{
                          $('#select_product').html('<option value="">Select brand first</option>'); 
                         }
    });

    });

</script>


</head>
<body>
    <div class="all-content-wrapper">
        <!-- Top Bar -->
        <header>
             <?php include_once("../../build/top-bar.php");?>  
        </header>
        <!-- #END# Top Bar -->
        <!-- Left Menu -->
            <?php include_once("../../build/left-menu.php");?> 
        <!-- #END# Left Menu -->
        <!-- Right Sidebar -->
            <?php include_once("../../build/right-sidebar.php");?> 
        <!-- #END# Right Sidebar -->



        <section class="content dashboard">
            <div class="page-heading">
                <h1>Manage Products</h1>
            </div>

            <div class="page-body">

                <div class="row clearfix">
                    <!-- e-commerce card form-->
                  <div class="container">
                        <div class="row">
                            <div class="col-md-10 mx-auto">

                                    <div class="card">
                                        <div class="card-body">

                                            <form>
                                                <div class="form-row">
                                                    <div class="form-group col-md-6">
                                                        <input type="hidden" name="pid" id="pid" value=""/>
                                                        <label>Date</label>
                                                        <input type="text" class="form-control" name="added_date" id="added_date" value="<?php echo date("Y-m-d"); ?>" readonly/>
                                                    </div>
                                                    <div class="form-group col-md-6">
                                                        <label>Product Name</label>
                                                        <input type="text" class="form-control" name="update_product" id="update_product" placeholder="Enter Product Name" required>
                                                    </div>
                                               </div>
                                                <div class="form-row">
                                                    <div class="form-group col-md-6">
                                                        <label>Product Category</label>
                                                        <select class="chosen selectpicker form-control" data-live-search="true" id="select_cat" name="select_cat" required>
                                                            <option value="" default selected>Select Category</option>


                                                        </select>
                                                    </div>
                                                    <div class="form-group col-md-6">
                                                        <label>Product Brand</label>
                                                        <select class="selectpicker form-control" id="select_brand" name="select_brand" required>
                                                        <option value="" default selected>Select Brand</option>



                                                        </select>

                                                    </div>
                                                </div>
                                                <div class="form-row">
                                                    <div class="form-group col-md-6">
                                                        <label>Product Price</label>
                                                        <input type="text" class="form-control" id="product_price" name="product_price" placeholder="Enter Price of Product" required/>
                                                    </div>

                                                    <div class="form-group col-md-6">
                                                        <label>Product Quantity</label>
                                                        <input type="text" class="form-control" id="product_qty" name="product_qty" placeholder="Enter Quantity" required/>
                                                    </div>

                                                    <div class="form-group col-md-6">
                                                        <button type="submit" class="btn btn-success"><i class="fa fa-plus">&nbsp;</i>Add Product</button>
                                                    </div>

                                                </div>

                                            </form>


                                        </div>
                                    </div>

                            </div>
                        </div>
                    </div>

                 <br>
                 <!-----#END# e-commerce carf form ---->
                    <?php
                    //Products Form
                    //include_once("modal_add_products.php");
                    ?>
                    <?php
                    //Products Form
                    //include_once("manage_modal_products.php");
                    ?>
                                    <!-- #END# Category -->
                                    <!-- To-Do List -->
                                    <!-- #END# To-Do List -->
                </div>

                <!-- Product Table -->
                <div class="panel panel-default">
                    <div class="panel-heading">Product LIST</div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table js-exportable">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Product</th>
                                            <th>Category</th>
                                            <th>Brand</th>
                                            <th>Price</th>
                                            <th>Stock</th>
                                            <th>Added Date</th>
                                            <th>Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody id="get_product">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                    <!-- #END# Product table -->
            </div>
        </section>
         <!-- Footer -->
         <footer>
            <?php include_once("../../build/footer.php");?> 
         </footer>
        <!-- #END# Footer -->
    </div>

    <!-- Jquery Core Js -->
    <script src="../../assets/plugins/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

    <!-- JQuery UI Js -->
    <script src="../../assets/plugins/jquery-ui/jquery-ui.js"></script>

    <!-- Bootstrap Core Js -->
    <script src="../../assets/plugins/bootstrap/dist/js/bootstrap.min.js"></script>

    <!-- Pace Loader Js -->
    <script src="../../assets/plugins/pace/pace.js"></script>

    <!-- Screenfull Js -->
    <script src="../../assets/plugins/screenfull/src/screenfull.js"></script>

    <!-- Metis Menu Js -->
    <script src="../../assets/plugins/metisMenu/dist/metisMenu.js"></script>

    <!-- Jquery Slimscroll Js -->
    <script src="../../assets/plugins/jquery-slimscroll/jquery.slimscroll.js"></script>

    <!-- Switchery Js -->
    <script src="../../assets/plugins/switchery/dist/switchery.js"></script>

    <!-- iCheck Js -->
    <script src="../../assets/plugins/iCheck/icheck.js"></script>

    <!-- Jquery Sparkline Js -->
    <script src="../../assets/plugins/jquery-sparkline/dist/jquery.sparkline.js"></script>

    <!-- Flot Chart Js -->
    <script src="../../assets/plugins/flot/jquery.flot.js"></script>
    <script src="../../assets/plugins/flot-spline/js/jquery.flot.spline.js"></script>
    <script src="../../assets/plugins/flot/jquery.flot.pie.js"></script>
    <script src="../../assets/plugins/flot/jquery.flot.categories.js"></script>
    <script src="../../assets/plugins/flot/jquery.flot.time.js"></script>

    <!-- JQuery Datatables Js -->
    <script src="../../assets/plugins/DataTables/media/js/jquery.dataTables.js"></script>
    <script src="../../assets/plugins/DataTables/media/js/dataTables.bootstrap.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/dataTables.buttons.min.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/buttons.bootstrap.min.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/buttons.flash.min.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/jszip.min.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/pdfmake.min.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/vfs_fonts.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/buttons.html5.min.js"></script>
    <script src="../../assets/plugins/DataTables/extensions/export/buttons.print.min.js"></script>

    <!-- Piety Js -->
    <script src="../../assets/plugins/peity/jquery.peity.js"></script>

    <!-- Custom Js -->
    <script src="../../assets/js/admin.js"></script>
    <script src="../../assets/js/pages/dashboard/dashboard.js"></script>

    <!-- Google Analytics Code -->
    <script src="../../assets/js/google-analytics.js"></script>

    <!-- Demo Purpose Only -->
    <script src="../../assets/js/demo.js"></script>
</body>
</html>

<?php
//fetch all country data from database
//Include database configuration file
include('../Alixia/database/db.php');

    $query = $mysqli->query("SELECT * FROM categories WHERE status = 1 ORDER BY category_name ASC");// select all categories from database 

    //Count total number of rows
    $rowCount = $query->num_rows;

    //Display states list
    if($rowCount > 0)

        {
    echo '<option value="">Select Category</option>';// initial message display{  
    //echo '<input type="text" >';// initial message display

        while($row = $query->fetch_assoc())
        {
            echo '<option value="'.$row['cid'].'">'.$row['category_name'].'</option>';// select category id & name from country table
        }
    }
    else
    {
        echo '<option value="">Category Not Available</option>'; //display when no data!
    }



?>

<?php
//Include database configuration file
include('../Alixia/database/db.php');

if(isset($_POST["cid"]) && !empty($_POST["cid"])){
    //Get all brand data
    $query = $mysqli->query("SELECT * FROM brands WHERE cid = ".$_POST['cid']." AND status = 1 ORDER BY brand_name ASC");

    //Count total number of rows
    $rowCount = $query->num_rows;

    //Display product list
    if($rowCount > 0){
        echo '<option value="">Select brand</option>';
        while($row = $query->fetch_assoc()){
            echo '<option value="'.$row['bid'].'">'.$row['brand_name'].'</option>';
        }
    }else{
        echo '<option value="">Brand not available</option>';
    }
}

if(isset($_POST["bid"]) && !empty($_POST["bid"])){
    //Get all product data
    echo "asdasd";
    $query = $mysqli->query("SELECT * FROM products WHERE bid = ".$_POST['bid']." AND status = 1 ORDER BY product_name ASC");

    //Count total number of rows
    $rowCount = $query->num_rows;

    //Display Product list
    if($rowCount > 0){
        echo '<option value="">Select product</option>';
        while($row = $query->fetch_assoc()){
            echo '<option value="'.$row['pid'].'">'.$row['product_name'].'</option>';
        }
    }else{
        echo '<option value="">Product not available</option>';
    }
}




?>

我尝试使用和编辑我在网上看到的Ajax代码,该代码似乎正在处理我在youtube上观看的视频,但对我没有帮助,请问我对这些代码有什么误解。

0 个答案:

没有答案