I want to make some kind of booking system. I am displaying all data about cars from the database with buttons(which is a link that directs to the booking page) in "boxes", each box is for one car. I want to get id of the car for which the user pressed the button in box where the car is.
Here is my code
<!-- Fetching data from rows -->
<?php
while($rows = $result->fetch_assoc())
{
?>
<div class="car_box">
<div class="car_title">
<p><b><?php echo $rows['Brand'],' ', $rows['Model'];?></b></p>
</div>
<div class="car_description">
<div class="car_details">
<!-- ENGINE CAPACITY -->
<p>
<b>Engine capacity: </b> <?php echo $rows['Engine_capacity']; ?> cm3
</p>
(...)
<!-- BOOKING -->
<div class="booking">
Book now
</div>
</div>
You could try adding a parameter to your link.
Book now
and retrieve it in your Bookings.php by using $_GET['id'].
Related
Here is my Html and PHP code, I've commented all the details, I want specific data depending on which button is clicked by the user, but the button is printed in a loop, whenever I try to access it gives the last updated data in submit button. because every time while loop executes, it is obvious to change values of $row variable, how can I manage to get appropriate values according to which submit button is clicked.
can it be done using an array?
any piece of code that can help?
<?php
require_once '../includes/header.php';
require_once '../includes/connection.php';
//i got data from table
$sql="select * from shoes";
$result = $con->query($sql);
?>
<html>
<main role="main">
<section class="sec-intro" role="section">
<h1>Products</h1>
</section>
<section class="sec-boxes" role="section">
<!-- I placed a PHP loop here -->
<?php
while ($row = $result->fetch_assoc()) {
?>
<article class="box">
<!-- Printing Data of Shoe -->
<img src="<?= $row['image'] ?>" width="250px" height="300px">
<h1> <?= $row['shoe_name'] ?></h1>
<?php
//cutting the long strings into short becasue shoe description was long
$des = $row['shoe_description'];
if (strlen($des)>70)
{
// truncate string
$stringCut = substr($des, 0, 90);
$endPoint = strrpos($stringCut, ' ');
$des = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0);
$des .= '... <a class= "link" href="search.php">Read More</a>';
}
?>
<p> <?= $des ?> </p>
<!------------------------------------------
----------------------------------------
---------- PROBLEM IS HERE -------------------
------------------------------------------
------------------------------------->
<input class="button" type="submit" name = "submit" value="Add to Cart" width= "150px"; />
<!-- THIS ADD TO CART BUTTON IS INSIDE LOOP
AND I WANT SHOE_ID AND SHOE_NAME OF THAT
SPECIFIC BUTTON OF SHOE SPECIFIC SHOE -->
</article>
<?php } ?>
<!-- PHP LOOP ENDED HERE -->
<?php
if(isset($_POST['submit']))
{
$id = $_POST['shoe_id']; //here i need the shoe id of that specific shoe.
}
?>
</section>
<!-- THIS WILL REMAIN SAME THROUGHOUT THE WEBSITE -->
</main>
<?php
require_once '../includes/footer.php';
?>
</html>
The image of the web page is attached for clarity:
page display
EDIT/UPDATE: The if(isset($_POST['submit'])) isn't working as well ??
If you want to redirect to another page how you have write in your comment then you have to use javascript. Change your submit button with:
<input class="button" type="button" onclick="location='your-next-page.php?id=<?=$row['shoe_name']?>'" value="Add to Cart" width= "150px"; />
And then you can retrieve the id by $_GET['id'];
If you want to post the id, then the you have to use a javascript function with ajax or fetch to send the id via post method.
I have a simple ticket sale registration system with 6 types of tickets and 3 different "physical" sales locations. Each order is inserted as a row in the database and stores the amount of each type of ticket along with the sale location, total cost and a datetime timestamp.
I want to display the total amount of each ticket type, that was sold within a given time frame along with the total cost of those tickets. I also want to filter the results based on sale location.
This is my db query:
"SELECT SUM(ticketType1), SUM(ticketType2), SUM(ticketType3),
SUM(ticketType4), SUM(ticketType5), SUM(ticketType6),
SUM(cost), saleLocation
FROM `orders`
WHERE time BETWEEN '2018-07-10 07:00:01'
AND '2018-07-11 07:00:00'"
Then I display it in a HTML table row:
<?php
while ($row = $result->fetch_assoc()) {
if($row["saleLocation"] == 'location1') { ?>
<div class="cell">
<?php echo $row["SUM(ticketType1)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType2)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType3)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType4)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType5)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType6)"] ?>
</div>
<div class="cell">
<?php echo number_format($row["SUM(cost)"], 0, "", "."); ?>
</div>
<?php } //end if
} // end while
?>
It works, but I'm trying to use an IF statement inside the WHILE loop to filter the result based on location, but the IF statement doesn't appear to have any effect and instead it displays the results from all 3 locations.
I know I can easily modify the query to achieve this, but I would rather not do that in this specific case.
I'm guessing that the problem still lies within the query, though?
Some help would be greatly appreciated.
I'm loading photos from database with mysql query. For default it load data from database with pagination.
<div class="col-md-10 bg col-md-push-2 ">
<div class="align_center gallery">
<?php
include "anj.php";
$sql = 'SELECT * FROM new_photos ;
/* function anjaan content code for loading photos .*/
anjaan($sql);
}
?>
</div>
<div class=" align_center ">
<div class=" col-md-12 pagination gallery">
<?php
echo $paginationctrl;
?>
</div>
</div>
Now I want when user click a button data should change with this
<?php
include "anj.php";
$sql = 'SELECT * FROM new_photos WHERE weight BETWEEN 10 AND 15';
anjaan($sql);
?>
Php is just server side, so i think u only will have two options.
1 - On click reload de page and send a post or get params to the application usign form and then load the page with the new query.
2 - If u want to do not reload te page, will be better to send an Ajax request to server side with JavaScript and then bring and replace the old content for the new one.
I have 3 divs, each with a different data attribute:
<div class="box">
<div class="item" data-category="#music"> CLICK </div>
</div>
<div class="box">
<div class="item" data-category="#movies"> CLICK </div>
</div>
.
.
.
I made script which activates a hidden dialog box:
$('.box').click(function() {
$('#dialogbox').show();
});
I have divs, with ids that are the same as a data-category attribute:
<div id="music"> ALL INFORMATION ABOUT MUSIC </div>
<div id="movies"> ALL INFORMATION ABOUT MOVIES </div>
.
.
.
My question:
How can I display information from all of the ALL INFORMATION divs in dialogbox by the clicked data-category?
Yes, you can
$('.box').click(function() {
var id = $(this).find('.item').data('category'); //replace with $(this).find('.item').attr('data-category') if fails
var message = $(id).html();
//now write your code here to push this message inside certain div of dialogbox, i assume message is the id
$("#message").html(message);
//then finally show
$('#dialogbox').show();
});
i need help to passing row from mysql database into div popup window?
how do i passing product id into popup div which i called through View?
For Example I Want Like This
i want to fetch product details into `product quick view popup window`
through product `ID`?
Here My Code
<div class="latest_products_sec">
<div class="latest_products">
<div class="title_box">
</div>
<!--Latest Products Slider -->
<div class="latest_pro_box">
<h4>Latest Shirt's Collection</h4>
<div class="latest_products_slider">
<?php
$queryshirt=mysql_query("select image,id from products
where cid='1' LIMIT 5") or die ('die shirt query');
while($rowshirt=mysql_fetch_array($queryshirt))
{
echo '<ul>';
echo '<li><img src="admin/'.$rowshirt['image'].'"
width="225" height="300" alt="" />
View</li>';
echo '</ul>';?>
}
?>
#shirt Div Popup Window
<div id="shirt" class="proquickview">
<span class="close_btn" onclick="parent.jQuery.fancybox.close();">Close</span>
<h2 class="title">quick view</h2>
<div class="quickviewinfo">
<?php
// I Need To Get ID Here
echo $id=$_REQUEST['id'];
?>
<div class="quickviewinforight">
<div class="titlerow">
<h2>Latest Shirt's Collection</h2>
<div class="start_ratings">
<div class="start_rating">
</div>
</div>
<div>
<div class="quick_review">
<h3>Quick Discription</h3>
<p>TEST.</p>
</div>
<div class="qty_row">
<div class="qty_field">
<label>Select Quantity</label>
<span>
<select name="S">
<option>5</option>
</select>
</span>
</div>
<br class="clear" />
<span class="total_price">Price <strong>$88.00</strong>
<del>$102.00</del></span>
ADD TO CART
</div>
<div class="total_price_row">
</div>
</div>
</div>
</div>
Javascript For Popup Window
$(document).ready(function() {
$(".view_btn").fancybox({
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
});
$(document).ready(function(){
// Cufon Functions //
Cufon.replace ('.latest_products_slider ul li a.view_btn',{hover:true});
});
It's hard to tell what is wrong as you have only given part of the story.
Fundamentally you need:
Action by the user (usually a click) triggers AJAX call sending a unique ID onclick="updatefunction(this.id) in a SPAN or DIV will do the trick:
<SPAN onclick="updatefunction(this.id)" id="1234">Your Stuff to update</SPAN>
The JS function updatefunction must send the detail/ID to a separate PHP script (you can use the original but this just makes it clunky) which queries your database on the ESCAPED data you send.
Once the data is ready, the JS will update the window/pop it up.
AFAICS you are missing the extra bit that actually does the querying or not applying a suitable onclick.
Why not have a look at the excellent W3Schools Ajax tutorial - it will help though does not use jQuery.