Bonjour à tous
Je commences des études en informatique, mais je suis passionnée que j’essaie de découvrir de moi même.
Dans ce sens je m'exerce sur un exemple et la j’essaie d'ajouter le recherche et la pagination sans succès.

Je demande votre aide

merci

index.php

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
//index.php
?>
<!DOCTYPE html>
<html>
	<head>
		<title>PHP Shopping Cart</title>
		<script src="js/jquery.min.js"></script>
		<link rel="stylesheet" href="css/bootstrap.min.css" />
		<script src="js/bootstrap.min.js"></script>
		<style>
                .popover
                {
                    width: 100%;
                    max-width: 800px;
                }
                </style>
	</head>
	<body>
		<div class="container">
			<br />
			<h3 align="center"><a href="#">PHP Shopping Cart</a></h3>
			<br />
			<nav class="navbar navbar-default" role="navigation">
				<div class="container-fluid">
					<div class="navbar-header">
						<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
						<span class="sr-only">Menu</span>
						<span class="glyphicon glyphicon-menu-hamburger"></span>
						</button>
						<a class="navbar-brand" href="/">PHP Shopping Cart</a>
					</div>
 
					<div id="navbar-cart" class="navbar-collapse collapse">
						<ul class="nav navbar-nav">
							<li>
								<a id="cart-popover" class="btn" data-placement="bottom" title="Shopping Cart">
									<span class="glyphicon glyphicon-shopping-cart"></span>
									<span class="badge"></span>
									<span class="total_price">$ 0.00</span>
								</a>
							</li>
						</ul>
					</div>
 
				</div>
			</nav>
			<div id="popover_content_wrapper" style="display: none">
				<span id="cart_details"></span>
				<div align="right">
					<a href="#" class="btn btn-primary" id="check_out_cart">
					<span class="glyphicon glyphicon-shopping-cart"></span> Check out
					</a>
					<a href="#" class="btn btn-default" id="clear_cart">
					<span class="glyphicon glyphicon-trash"></span> Clear
					</a>
				</div>
			</div>
 
			<div id="display_item">
 
 
			</div>
 
		</div>
	</body>
</html>
 
<script>  
$(document).ready(function(){
 
        load_product();
 
        load_cart_data();
    
        function load_product()
        {
                $.ajax({
                        url:"fetch_item.php",
                        method:"POST",
                        success:function(data)
                        {
                                $('#display_item').html(data);
                        }
                });
        }
 
        function load_cart_data()
        {
                $.ajax({
                        url:"fetch_cart.php",
                        method:"POST",
                        dataType:"json",
                        success:function(data)
                        {
                                $('#cart_details').html(data.cart_details);
                                $('.total_price').text(data.total_price);
                                $('.badge').text(data.total_item);
                        }
                });
        }
 
        $('#cart-popover').popover({
                html : true,
        container: 'body',
        content:function(){
                return $('#popover_content_wrapper').html();
        }
        });
 
        $(document).on('click', '.add_to_cart', function(){
                var product_id = $(this).attr("id");
                var product_name = $('#name'+product_id+'').val();
                var product_price = $('#price'+product_id+'').val();
                var product_quantity = $('#quantity'+product_id).val();
                var action = "add";
                if(product_quantity > 0)
                {
                        $.ajax({
                                url:"action.php",
                                method:"POST",
                                data:{product_id:product_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity, action:action},
                                success:function(data)
                                {
                                        load_cart_data();
                                        alert("Item has been Added into Cart");
                                }
                        });
                }
                else
                {
                        alert("lease Enter Number of Quantity");
                }
        });
 
        $(document).on('click', '.delete', function(){
                var product_id = $(this).attr("id");
                var action = 'remove';
                if(confirm("Are you sure you want to remove this product?"))
                {
                        $.ajax({
                                url:"action.php",
                                method:"POST",
                                data:{product_id:product_id, action:action},
                                success:function()
                                {
                                        load_cart_data();
                                        $('#cart-popover').popover('hide');
                                        alert("Item has been removed from Cart");
                                }
                        })
                }
                else
                {
                        return false;
                }
        });
 
        $(document).on('click', '#clear_cart', function(){
                var action = 'empty';
                $.ajax({
                        url:"action.php",
                        method:"POST",
                        data:{action:action},
                        success:function()
                        {
                                load_cart_data();
                                $('#cart-popover').popover('hide');
                                alert("Your Cart has been clear");
                        }
                });
        });
    
});
 
</script>

fetch item.php

Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
 
//fetch_item.php
 
include('database_connection.php');
 
$query = "SELECT * FROM tbl_product ORDER BY id DESC";
 
$statement = $connect->prepare($query);
 
if($statement->execute())
{
	$result = $statement->fetchAll();
	$output = '';
	foreach($result as $row)
	{
		$output .= '
		<div class="col-md-3" style="margin-top:12px;">  
            <div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px; height:350px;" align="center">
            	<img src="images/'.$row["image"].'" class="img-responsive" /><br />
            	<h4 class="text-info">'.$row["name"].'</h4>
            	<h4 class="text-danger">$ '.$row["price"] .'</h4>
            	<input type="text" name="quantity" id="quantity' . $row["id"] .'" class="form-control" value="1" />
            	<input type="hidden" name="hidden_name" id="name'.$row["id"].'" value="'.$row["name"].'" />
            	<input type="hidden" name="hidden_price" id="price'.$row["id"].'" value="'.$row["price"].'" />
            	<input type="button" name="add_to_cart" id="'.$row["id"].'" style="margin-top:5px;" class="btn btn-success form-control add_to_cart" value="Add to Cart" />
            </div>
        </div>
		';
	}
	echo $output;
}
 
 
?>

Au cas ou quelqu'un voudrais m'aider
php-ajax-shopping-.rar