I'm trying to display one of these boxes : (Image here) for every product. But when I add another product in the database, it doesn't seem to add another on view for my products page. Here you see my database, but only one image on my products page. The page looks as same as the first image posted above. If anyone knows why my products aren't showing for each product, only the first one, then please let me know. I know my code is not secure, not neat. I will do that after I'm done getting this to work so don't judge me on that. Only the issue I asked. Thanks.
My PHP code is all in this one function which I call in my div containers :
function grabProducts($con) {
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="col-md-12" id="please_wait">
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title"><i>Loading, Please Wait...</i></h3>
</div>
<div class="panel-body">
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#please_wait').fadeOut(7000);
$('#content_purchase').hide(0).delay(5000).fadeIn("slow");
});
</script>
<?php
$users = $this->grabUserInfos($con);
foreach ($users as $user) {
$username = $user[1];
$email = $user[3];
}
$site_config = new site_config();
$member_config = new member_config();
$result = mysqli_query($con, "SELECT * FROM products");
$count = mysqli_num_rows($result);
$site_callback = $site_config->grabSiteSettings_manual($con, 'site_url').'/pizza/includes/checkout.php';
$site_return_success = $site_config->grabSiteSettings_manual($con, 'site_url').'/pizza/products.php?status=complete';
$site_return_canceled = $site_config->grabSiteSettings_manual($con, 'site_url').'/pizza/products.php?status=canceled';
// See if there are any products in the database
if ($count > 0) {
// While loop for each product element
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
$description = $row['description'];
$picture = $row['picture_location'];
$price = $row['price'];
$stock_monitering = $row['stock_monitering'];
//$stock = $row['stock'];
// Count the number links in each product
$product_count = mysqli_query($con, "SELECT COUNT(*) FROM ebook WHERE used_status = '0'");
$row_product_count = mysqli_fetch_row($product_count);
$count_product_stock = $row_product_count[0];
$stock = $count_product_stock;
$new_stock = $stock - 1;
$getValidatedCheck_ = mysqli_query($con, "SELECT txn_id, hasValidated, item_name, amount, currency, payment_date FROM payment_logs WHERE userId = '$username' ORDER BY id DESC LIMIT 1");
// Count the number of payment_logs that correspond to the logged in user
$payment_log_count = mysqli_query($con, "SELECT COUNT(*) FROM payment_logs WHERE userId = '$username'");
$row = mysqli_fetch_row($payment_log_count);
$count_payment_logs = $row[0];
$now = strtotime("-10 minutes");
// If there are no transactions for that user show the products like normal
if($count_payment_logs <= 0) {
// If there is not enough stock, show out of stock
if($stock <= 0) {
$display = "out_of_stock";
} else if($stock > 0) {
$display = "show_products";
}
} else if($count_payment_logs >= 1) {
// While loop for our successful payment_logs for each user
while ($row = mysqli_fetch_array($getValidatedCheck_)) {
$txn_id = $row['txn_id'];
$validated_check = $row['hasValidated'];
$item_name = $row['item_name'];
$item_price = $row['amount'];
$item_currency = $row['currency'];
$payment_date = $row['payment_date'];
// If they've not already seen the success message, show them it now and update their hasValidated from 0 to 1 so they don't see it again
if ($validated_check == '0') {
// If stock monitering is on, update our stock to 1 less than we had before the purchase
if($stock_monitering == '1') {
mysqli_query($con, "UPDATE products SET stock = '$new_stock' WHERE name = '$name'");
}
$product_count = mysqli_query($con, "UPDATE ebook SET used_status = '1', assigned_to = '$username', transaction_id = '$txn_id' WHERE used_status = '0'");
$display = "show_success";
} else {
if($stock <= 0) {
$display = "out_of_stock";
} else if($stock > 0) {
$display = "show_products";
}
}
}
}
switch($display) {
case "show_products":
?>
<div class="col-md-3" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Price: <i>$<?php echo $price; ?></i>
<div class="fRight" style="float: right;"><i><?php echo $name; ?></i> Stock
(<?php echo $stock; ?>)
</div>
</h3>
</div>
<center>
<div class="panel-body">
<img src="<?php echo $picture; ?>"
style="width: 85%; height: 100px; margin: 15px 0px 15px 0px; border-radius: 5px; border: 2px solid #ED4949;">
<form name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $site_config->grabSiteSettings_manual($con, 'paypal_address'); ?>">
<input type="hidden" name="item_name" value="<?php echo $name; ?>">
<input type="hidden" name="item_number" value="<?php echo $id; ?>">
<input type="hidden" name="amount" value="<?php echo $price; ?>">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="username=<?php echo $username; ?>&product= <?php echo $name; ?>">
<input type="hidden" name="notify_url" value="<?php echo $site_callback; ?>">
<input type="hidden" name="return" value="<?php echo $site_return_success; ?>">
<input type="hidden" name="cancel_return" value="<?php echo $site_return_canceled; ?>">
<button type="submit" class="btn btn-danger"
style="vertical-align : bottom; margin-bottom: 15px; display: block; width: 85%;">
<i class="fa fa-paypal"></i>aypal
</button>
<form>
</div>
</center>
</div>
</div>
';
break;
case "show_success":
?>
<div class="col-md-12" id="content_purchase" style="display: none;">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title"><i>PAYMENT SUCCESS!</i></h3>
</div>
<div class="panel-body">
<p>You've successfully purchased <i><?php echo $item_name; ?></i> for <i><?php echo $item_price; ?> <i><?php echo $item_currency; ?></i>. We have emailed you your receipt to <?php echo $email; ?>. You can click here to download your purchased files.<br>Click here to purchase again.</p>
</div>
</div>
</div>
<?php
mysqli_query($con, "UPDATE payment_logs SET hasValidated = '1' WHERE userId = '$username' ORDER BY id DESC LIMIT 1");
break;
case "no_products":
?>
<div class="col-md-12" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title"><i>Currently No Products For Sale</i></h3>
</div>
<div class="panel-body">
<p>There are currently no products up for sale.</p>
</div>
</div>
</div>
<?php
break;
case "out_of_stock":
?>
<div class="col-md-3" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Price: <i>$<?php echo $price; ?></i>
<div class="fRight" style="float: right;"><i><?php echo $name; ?></i> Stock
(<?php echo $stock; ?>)
</div>
</h3>
</div>
<center>
<div class="panel-body">
<img src="<?php echo $picture; ?>"
style="width: 85%; height: 100px; margin: 15px 0px 15px 0px; border-radius: 5px; border: 2px solid #ED4949;">
<p style="margin: 0px 15px 0px 15px;"><i><?php echo $name; ?></i> is currently out of stock. Please come back later and try again.</p>
</div>
</center>
</div>
</div>
<?php
break;
}
}
} else {
$display = 'no_products';
}
}
You should also loop your UI box so that you can have the same number of the product in the database and the box printed.
$sql = "Select * from product";
foreach('fetch all product from DB'){
?>
<div class="col-md-3" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Price: <i>$<?php echo $price; ?></i>
<div class="fRight" style="float: right;"><i><?php echo $name; ?></i> Stock
(<?php echo $stock; ?>)
</div>
</h3>
</div>
<center>
<div class="panel-body">
<img src="<?php echo $picture; ?>"
style="width: 85%; height: 100px; margin: 15px 0px; border-radius: 5px; border: 2px solid #ED4949;">
<form name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $site_config->grabSiteSettings_manual($con, 'paypal_address'); ?>">
<input type="hidden" name="item_name" value="<?php echo $name; ?>">
<input type="hidden" name="item_number" value="<?php echo $id; ?>">
<input type="hidden" name="amount" value="<?php echo $price; ?>">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="username=<?php echo $username; ?>&product= <?php echo $name; ?>">
<input type="hidden" name="notify_url" value="<?php echo $site_callback; ?>">
<input type="hidden" name="return" value="<?php echo $site_return_success; ?>">
<input type="hidden" name="cancel_return" value="<?php echo $site_return_canceled; ?>">
<button type="submit" class="btn btn-danger"
style="vertical-align : bottom; margin-bottom: 15px; display: block; width: 85%;">
<i class="fa fa-paypal"></i>aypal
</button>
<form>
</div>
</center>
</div>
</div>
<?php
} //end loop
sorry I forgot the syntax. :D but that's the logic.
Related
I have been struggling to figure out the mystery behind this.
Unable to POST form data when I add name to a particular input field. I been starring at the screen for hours to figure out what went wrong.
My Code goes as,
Form Page:
<form action="upload.php" method="POST">
<div class="customer_records">
<div class="customer_records_sub">
<input type="text" list="o_id" name="o_id[]" class="mb-2 mr-sm-2 o_id_input" placeholder="Order ID"
style="width: auto;padding: 10px 50px;display: inline-block;font-size: 16px;
border: 1px solid lightgray;border-radius:5px;vertical-align: text-bottom;background: none;">
<datalist id="o_id">
<?php
$sql_o_id = "SELECT DISTINCT(o_id) FROM quotes";
$result_o_id = $conn->query($sql_o_id);
if ($result_o_id->num_rows > 0) {
while($row_o_id = $result_o_id->fetch_assoc()) {
$o_id = $row_o_id["o_id"];
?>
<option value="<?= $o_id; ?>">
<?php } } else { } ?>
</datalist>
<div class="asins_visible_input mb-2 mr-sm-2"
style="width: auto;padding: 10px 50px;display: inline-block;font-size: 16px;
border: 1px solid lightgray;border-radius:5px;vertical-align: text-bottom;
background: none;height: 45px;min-width: 300px;" >
</div>
<br/>
<div class="asins_list" style="display:none;height: auto;overflow: auto;width: auto;
border: 1px solid lightgray;padding: 2%;border-radius: 5px;
margin-left: 24%;min-width: 400px;">
<?php
$sql_asin_id = "SELECT * FROM quotespos";
$result_asin_id = $conn->query($sql_asin_id);
if ($result_asin_id->num_rows > 0) {
while($row_asin_id = $result_asin_id->fetch_assoc()) {
$asin_id = $row_asin_id["id"];
$asin_p_id = $row_asin_id["p_id"];
$asin_o_id = $row_asin_id["o_id"];
if($asin_p_id == '' || $asin_p_id == NULL) {
$asin_p_id = '(BLANK)';
} else {
$asin_p_id = $asin_p_id;
}
?>
<div class="asin_id indi_asin_<?= $asin_o_id; ?>" style="display:none;padding-left:10px;">
<input type="checkbox" class="asins_input_checkbox" data-id="<?= $asin_id; ?>" data-pid="<?= $asin_p_id; ?>" style="display:inline-block;width: 20px;height: 20px;" />
<p style="display:inline-block;padding-top: 2px;font-size: 16px;vertical-align: super;"><?= $asin_p_id; ?></p>
<div class="asins_div_percentile"
style="diplay:inline-block;float:right;display:none;">
<i class="fa fa-chevron-right" aria-hidden="true"
style="margin-top: 9px;margin-left: 8px;font-size: 14px;"></i>
<input class="asins_div_percentile_input" name="tada"
style="width: 50px;margin-left: 30px;vertical-align: top;
border: 1px solid gray;font-size: 16px;
border-radius:5px;border:1px solid gray;text-align:center;"
type="text" placeholder="%" />
</div>
<br/>
</div>
<?php $sl++; } } else { } ?>
<input type="hidden" name="asins[]" class="asins_hidden_input" />
</div>
</div>
</div>
<input type="hidden" name="bywhom" value="0" />
<input type="hidden" name="date" value="06/12/201" />
<button type="submit" name="submit" class="btn btn-primary mb-2 expense_form_btn"
style="margin-top: 0.8%;font-size:16px;">Submit</button>
</form>
Upload.php page:
$date = $_POST["date"];
$bywhom = $_POST["bywhom"];
echo $bywhom;
In the above form page, forget the array and all, they all work perfectly fine the moment i remove the name tag from the input tag with class asins_div_percentile_input, But the moment I keep something inside the name tag of that asins_div_percentile_input input, form gets submitted but none of the values gets posted. not even the normal input tag values like date mentioned above.
I don't understand what went wrong. Hope I was clear.
Any help is greatly appreciated.
After thinking a bit, I found a way around. Instead of forcing it to send all the empty fields and then take only the fields which have values, I removed the empty fields from DOM at the time of submission.
$(".form_submit_btn").click(function() {
$(".form_submit_btn").prop("disabled", true);
$('.main_parent').find('.asins_input_checkbox').each(function () {
if($(this).prop("checked")) { } else {
$(this).parent().remove();
}
});
$("#add_expense_form").submit();
});
Works fine. Thanks to all who literally taught me a lot through this query. Appreciate your time.
I am currently building eCommerce site using CI HMVC method. I completed it for computer design and all back-end. It work perfectly. But my dessign is terrible for mobile so i decided to write jquery mobile code. I almost complete the code in jquery mobile but i got i problem which i cannot solve.
I have the form which is use to add the item into the cart. For this i have add to cart function which has view file add_to_Cart.php whis has actual form. After submitting form goes to store_basket/add_to_basket function. Here i writ code to sore the comming information to store_basket table. Then it redirect the page to another controller cart where i have view file of list of items which is in cart.
when i submit the form it store item in store_basketm table. Then it show the view of cart controller but the url is localhost/shop/store_basket/add_to_basket Which should be localhost/shop/cart. But despite of url localhost/shop/store_basket/add_to_basket it show the contents of localhost/shop/cart
<?php $form_location = base_url().'store_basket/add_to_basket'; ?>
<div id="cart" style="background-color: #ddd; border-spacing: 7px; padding: 7px; color: black;">
<form ajax-date="false" data-url="true" action="<?= $form_location ?>" method="POST">
<table class="table">
<tr>
<td>ID: </td>
<td><?php echo $item_id ?></td>
</tr>
<input type="hidden" name="item_id" value="<?php echo $item_id ?>">
<input type="hidden" name="item_title" value="<?php echo $item_title ?>">
<?php if($num_colour > 0): ?>
<tr>
<td style="padding-top: 20px;">Colour: </td>
<td style="margin-left: 50px;">
<?php
$status = '';
$additional_dd_code = 'name="select-choice-mini" id="select-choice-mini" data-mini="true" data-inline="true"';
echo form_dropdown('item_colour', $colour_options, $submitted_colour, $additional_dd_code);
?>
</td>
</tr>
<?php endif; ?>
<?php if($num_size > 0): ?>
<tr>
<td style="padding-top: 20px;">Size: </td>
<td style="margin-left: 50px;">
<?php
$status = '';
$additional_dd_code = 'name="select-choice-mini" id="select-choice-mini" data-mini="true" data-inline="true" style="background-color: white;"';
echo form_dropdown('item_size', $size_options, $submitted_size, $additional_dd_code);
?>
</td>
</tr>
<?php endif; ?>
<tr>
<td>Price: </td>
<td><?= $item_price ?></td>
</tr>
<input type="hidden" name="price" value="<?= $item_price ?>">
<tr>
<td style="padding-top: 20px;">Qty: </td>
<td>
<input type="number" name="item_qty" value="1" min="1" required>
</td>
</tr>
</table>
<!-- <a rel="external" href=""><input name="submit" value="Submit" class="btn"></a> -->
<button type="submit" name="submit" value="Submit" id="cart-btn" class="ui-shadow ui-btn ui-corner-all" style="margin-top: 20px; width: 75%; margin-left: 30px;"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Add To Basket</button>
<?php echo form_close() ?>
store_basket/add_to_basket
function add_to_basket() {
// var_dump($_POST); exit;
$this->load->module('site_settings');
$this->load->library('session');
$this->load->module('site_security');
$is_mobile = $this->site_settings->is_mobile_device();
$submit = $this->input->post('submit', TRUE);
if($submit == "Submit"){
//library for form validation
$this->load->library('form_validation');
//validation rules
$this->form_validation->set_rules('item_colour', 'Item Color', 'numeric');
$this->form_validation->set_rules('item_size', 'Item Size', 'numeric');
$this->form_validation->set_rules('item_qty', 'quantity', 'required|numeric');
$this->form_validation->set_rules('item_id', 'Item_id', 'required|numeric');
if($this->form_validation->run($this)) {
// echo "Success"; exit;
$data = $this->_fetch_the_data();
$this->_insert($data);
redirect('cart');
} else {
// echo "Fail"; exit;
$refer_url = $_SERVER['HTTP_REFERER'];
$error_msg = validation_errors("<p style='color: red;'>","</p>");
$this->session->set_flashdata('item', $error_msg);
redirect('cart');
}
}
}
cart/index.php
function index() {
// echo "here"; exit;
$this->load->module('site_settings');
$is_mobile = $this->site_settings->is_mobile_device();
$data['flash'] = $this->session->flashdata('item');
$data['view_files'] = "cart";
if($is_mobile==TRUE) {
$data['view_files'] .= "_jqm";
$template = 'public_jqm';
} else {
$template = 'public_boostrap';
}
$token = $this->uri->segment(3);
if($token!='') {
$session_id = $this->_check_and_get_session_id($token);
} else {
$session_id = $this->session->session_id;
}
$this->load->module('site_security');
$shopper_id = $this->site_security->_get_user_id();
if(!is_numeric($shopper_id)) {
$shopper_id = 0;
}
$table = 'store_basket';
$data['query'] = $this->_fetch_cart_contents($session_id, $shopper_id, $table);
//count the items in basket or cart
$data['num_rows'] = $data['query']->num_rows();
$data['showing_statement'] = $this->_get_showing_statement($data['num_rows']);
$this->load->module('templates');
$this->templates->$template($data);
}
I have a products table where I have products being listed into. I want to create a peice of code that will show the same style but different price, name, description, picture for each product. I have create a peice of code that sort of does this. My code displays only the first in the row. I need to list all of them. My code is :
function grabProducts($con) {
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="col-md-12" id="please_wait">
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title"><i>Loading, Please Wait...</i></h3>
</div>
<div class="panel-body">
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#please_wait').fadeOut(7000);
$('#content_purchase').hide(0).delay(5000).fadeIn("slow");
});
</script>
<?php
$users = $this->grabUserInfos($con);
foreach ($users as $user) {
$username = $user[1];
$email = $user[3];
}
$site_config = new site_config();
$member_config = new member_config();
$result = mysqli_query($con, "SELECT * FROM products");
$count = mysqli_num_rows($result);
// See if there are any products in the database
if ($count > 0) {
// While loop for each product element
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
$description = $row['description'];
$picture = $row['picture_location'];
$price = $row['price'];
$stock_monitering = $row['stock_monitering'];
$stock = $row['stock'];
$new_stock = $stock - 1;
$url_path = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url_path_naked = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH).'/pizza/products.php';
$getValidatedCheck_ = mysqli_query($con, "SELECT txn_id, hasValidated, item_name, amount, currency, payment_date FROM payment_logs WHERE userId = '$username' ORDER BY id DESC LIMIT 1");
$count_success_payment = mysqli_num_rows($getValidatedCheck_);
// While loop for our successful payment_logs for each user
while ($row = mysqli_fetch_array($getValidatedCheck_)) {
$txn_id = $row['txn_id'];
$validated_check = $row['hasValidated'];
$item_name = $row['item_name'];
$item_price = $row['amount'];
$item_currency = $row['currency'];
$payment_date = $row['payment_date'];
$now = strtotime("-10 minutes");
// If there is not enough stock, show out of stock
if($stock <= 0) {
$display = 'out_of_stock';
} else if($stock > 0 && $now > strtotime($payment_date)) {
$display = 'show_products';
}
// If there are no transactions for that user show the products like normal
if($count_success_payment == 0) {
// If they've not already seen the success message, show them it now and update their hasValidated from 0 to 1 so they don't see it again
if ($validated_check == '0') {
// If stock monitering is on, update our stock to 1 less than we had before the purchase
if($stock_monitering == '1') {
mysqli_query($con, "UPDATE products SET stock = '$new_stock' WHERE name = '$name'");
}
$display = 'show_success';
}
}
}
switch($display) {
case "show_products":
?>
<div class="col-md-3" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Price: <i>$<?php echo $price; ?></i>
<div class="fRight" style="float: right;"><i><?php echo $name; ?></i> Stock
(<?php echo $stock; ?>)
</div>
</h3>
</div>
<center>
<div class="panel-body">
<img src="<?php echo $picture; ?>"
style="width: 85%; height: 100px; margin: 15px 0px 15px 0px; border-radius: 5px; border: 2px solid #ED4949;">
<form name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business"
value="<?php $site_config->grabSiteSettings($con, 'paypal_address'); ?>">
<input type="hidden" name="item_name" value="<?php echo $name; ?>">
<input type="hidden" name="item_number" value="<?php echo $id; ?>">
<input type="hidden" name="amount" value="<?php echo $price; ?>">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="username=<? echo $username; ?>&status=<? echo $checkout_status; ?>&product=<? echo $name; ?>">
<input type="hidden" name="notify_url" value="https://benzaofficial.com/pizza/includes/checkout.php">
<input type="hidden" name="return"
value="<?php $site_config->grabSiteSettings($con, 'site_url'); ?>/pizza/products.php?status=complete">
<input type="hidden" name="cancel_return"
value="<?php $site_config->grabSiteSettings($con, 'site_url'); ?>/pizza/products.php?status=canceled">
<button type="submit" class="btn btn-danger"
style="vertical-align : bottom; margin-bottom: 15px; display: block; width: 85%;">
<i class="fa fa-paypal"></i>aypal
</button>
<form>
</div>
</center>
</div>
</div>
<?php
break;
case "show_success":
?>
<div class="col-md-12" id="content_purchase" style="display: none;">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title"><i>PAYMENT SUCCESS!</i></h3>
</div>
<div class="panel-body">
<p>You've successfully purchased <i><?php echo $item_name; ?></i> for <i><?php echo $item_price; ?> <i><?php echo $item_currency; ?></i></i> We have emailed you your receipt to <?php echo $email; ?>. You can click here to download your purchased files.<br>Click here to purchase again.</p>
</div>
</div>
</div>
<?php
mysqli_query($con, "UPDATE payment_logs SET hasValidated = '1' WHERE userId = '$username' ORDER BY id DESC LIMIT 1");
break;
case "no_products":
?>
<div class="col-md-12" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title"><i>Currently No Products For Sale</i></h3>
</div>
<div class="panel-body">
<p>There are currently no products up for sale.</p>
</div>
</div>
</div>
<?php
break;
case "out_of_stock":
?>
<div class="col-md-3" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Price: <i>$<?php echo $price; ?></i>
<div class="fRight" style="float: right;"><i><?php echo $name; ?></i> Stock
(<?php echo $stock; ?>)
</div>
</h3>
</div>
<center>
<div class="panel-body">
<img src="<?php echo $picture; ?>"
style="width: 85%; height: 100px; margin: 15px 0px 15px 0px; border-radius: 5px; border: 2px solid #ED4949;">
<p><i><?php echo $name; ?></i> is currently out of stock. Please come back later and try again.</p>
</div>
</center>
</div>
</div>
<?php
break;
}
}
} else {
$display = 'no_products';
}
}
first you need a function dat select all of your products like this one
function showproducts($conn,$id){
$req="SELECT * FROM products ";
$liste=$conn->query($req);
return $liste->fetchAll();
}
than you should call this function :
$list=$cc->showproducts($cc->conn);
and foreach row you can show all columns
<?php
foreach ($list as $l){ ?>
<tr>
<td><?php echo $l[0] ;?> </td>
<td><?php echo $l[1] ;?> </td>
<td><?php echo $l[2] ;?> </td>
<td><?php echo $l[3] ;?> </td>
<td><?php echo $l[7] ;?> </td>
</tr>
<?php } ?>
I created a website selling components. Each component has 9 products. How can I add a dropdown button which can arrange the product showing by its Price or Name?
<?php
$query = "SELECT * FROM products ORDER BY id ASC";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<div class="col-md-4">
<form method="post" action="shop.php?action=add&id=<?php echo $row["id"]; ?>">
<div style="border: 1px solid #eaeaec; margin: -1px 19px 3px -1px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); padding:10px;" align="center">
<h5 class="text-info"><?php echo $row["p_name"]; ?></h5>
<img src="<?php echo $row["image"]; ?>" class="img-responsive">
<h5 class="text-danger">$ <?php echo $row["price"]; ?></h5>
<div class="col-xs-8">
<input type="text" name="quantity" class="form-control" value="1">
</div>
<input type="hidden" name="hidden_name" value="<?php echo $row["p_name"]; ?>">
<input type="hidden" name="hidden_price" value="<?php echo $row["price"]; ?>">
<input type="submit" name="add" class="btn btn-primary" value="Add to Cart" align="right">
</div>
</form>
</div>
<?php
}
}
?>
<?php
}
?>
</div>
</div>
Perhaps you could use Javascript as well and add a few select boxes to give Users the chance to choose the Attribute they want to sort by and also the Direction of the Sorting as in ASC or DESC. The Code Snippet below might shed some light:
<?php
$query = "SELECT * FROM products ORDER BY id ASC";
$result = mysqli_query($connect, $query);
// CREATE VARIABLES TO HOLD THE SELECT OPTIONS VALUES FOR THE SORTING...
$sortParam1 = 'price';
$sortParam2 = 'name';
$sortDir1 = 'ASC';
$sortDir2 = 'DESC';
// START BUILDING THE OUTPUT...
$output = "<div class='col-md-12'>"; //<== WRAPPER FOR SORING & DIRECTION BOXES
$output .= "<form method='post' action='' id='sorting_form'>"; //<== FORM FOR THE SORTING: SUBMITS TO SAME SCRIPT
// SORTING
$output .= "<div class='col-md-6'>";
$output .= "<select name='sorting' id='sorting'class='form-control'>";
$output .= "<option value='id'>Sorting</option>";
$output .= "<option value='{$sortParam1}'>{$sortParam1}</option>";
$output .= "<option value='{$sortParam2}'>{$sortParam2}</option>";
$output .= "</select>";
$output .= "</div>";
// DIRECTION
$output .= "<div class='col-md-6'>";
$output .= "<select name='direction' id='direction'class='form-control'>";
$output .= "<option value='ASC'>Sort Direction</option>";
$output .= "<option value='{$sortDir1}'>{$sortDir1}</option>";
$output .= "<option value='{$sortDir2}'>{$sortDir2}</option>";
$output .= "</select>";
$output .= "</div>";
$output .= "</form>"; //<== CLOSE SORTING FORM...
$output .= "</div>"; //<== CLOSE WRAPPER...
$rowData = "";
// WE USE JQUERY BELOW TO SUBMIT THE SORTING FORM ONCE USER
// SELECTS ANY OPTION FROM.... SO WE NOW HANDLE THAT SCENARIO HERE USING PHP
if(isset($_POST['sorting']) || isset($_POST['direction']) ){
$sortDirection = isset($_POST['direction']) ? $_POST['direction'] : $sortDir1; // DEFAULTS TO ASC
$sortField = isset($_POST['sorting']) ? $_POST['sorting'] : 'id'; // DEFAULTS TO id
$query = "SELECT * FROM products ORDER BY {$sortField} {$sortDirection}";
$result = mysqli_query($connect, $query);
}
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)) {
// USE HEREDOC TO CAPTURE THE DATA WITHIN THE LOOP...
$rowData .=<<<R_DATA
<div class="col-md-4">
<form method="post" action="shop.php?action=add&id={$row["id"]}">
<div style="border: 1px solid #eaeaec; margin: -1px 19px 3px -1px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); padding:10px;" align="center">
<h5 class="text-info">{$row["p_name"]}</h5>
<img src="{$row["image"]}" class="img-responsive">
<h5 class="text-danger">\$ {$row["price"]}</h5>
<div class="col-xs-8">
<input type="text" name="quantity" class="form-control" value="1">
</div>
<input type="hidden" name="hidden_name" value="{$row["p_name"]}">
<input type="hidden" name="hidden_price" value={$row["price"]}">
<input type="submit" name="add" class="btn btn-primary" value="Add to Cart" align="right">
</div>
</form>
</div>
R_DATA;
} // CLOSE WHILE LOOP
} // CLOSE IF CONDITIONAL LOGIC
// ADD THE DATA GATHERED FROM WHILE LOOP ($rowData) TO THE OUTPUT: $output
$output .= $rowData;
$output .= "</div>\n</div>"; // THESE APPEAR IN YOUR CODE BUT SEEM IRRELEVANT HERE...
// DISPLAY THE OUTPUT
echo $output;
?>
<!-- ENTER JAVASCRIPT: JQUERY -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js" integrity="sha384-I6F5OKECLVtK/BL+8iSLDEHowSAfUo76ZL9+kGAgTRdiByINKJaqTPH/QVNS1VDb" crossorigin="anonymous"></script>
<script type="text/javascript">
(function($){
$(document).ready(function(e){
var sortForm = $("#sorting_form");
var sortBox = $("#sorting");
var directionBox = $("#direction");
var bothBoxes = sortBox.add(directionBox);
// IF EITHER OF THE SORTING OR DIRECTION IS CHANGED
// JUST SUBMIT THE FORM
bothBoxes.on("change", function(evt){
sortForm.submit();
});
});
})(jQuery);
</script>
I want show checkbox as a grid without scrolling the page. I am developing a attendance reporting page which shows student name and checkbox with values from database. I want to show its in a grid like this:
My code shows like this:
My code:
<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php
while ($row = mysql_fetch_assoc($res)){?>
<th>
<input type="checkbox" class="input" id="input
<?php echo $row['st_id']; ?>"
name="student[]" value="<?php echo $row['st_id']; ?>"
checked="checked" >
<?php echo $row['st_name'] ; ?>
<label for="input<?php echo $row['st_id']; ?>">
</label>
</th>
This code take both name and checkbox id from the database..Anybody please help
You can use floating DIVs instead of table:
<style>
.inputDiv{
float: left;
padding: 5px;
margin: 5px;
border: 1px solid black;
}
</style>
<?php while ($row = mysql_fetch_assoc($res)) { ?>
<div class="inputDiv">
<input type="checkbox" class="input" id="input<?php echo $row['st_id']; ?>" name="student[]" value="<?php echo $row['st_id']; ?>" checked="checked" > <?php echo $row['st_name']; ?>
<label for="input<?php echo $row['st_id']; ?>"></label>
</div>
<?php } ?>
This will reorder automatically all DIVs depending of user's screen resolution.
You can use it like this:
<table border="1" cellspacing="2" cellpadding="5" summary="">
<?php
$counter = 1;
while ($row = mysql_fetch_assoc($res)){
if($number==1 ) {
echo '<tr>';
}
if($number %6 == 0) {
echo '</tr><tr>';
}
?>
<th> <input type="checkbox" class="input" id="input<?php echo $row['st_id']; ?>" name="student[]" value="<?php echo $row['st_id']; ?>" checked="checked" > <?php echo $row['st_name'] ; ?> <label for="input<?php echo $row['st_id']; ?>"></label></th>
<?php
$counter++;
if($number==0 || $number %6 == 0) {
echo '</tr>';
}
}
?>
</tr>
</table>