How do I to display the latest booking result where $date > strtotime("now"), as I can only display the booking records.
This is my PHP code
$mysqli = new mysqli("", "", "", "");
$stmt = $mysqli->prepare("SELECT bookingid, date, slot, location FROM booking WHERE username=?");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($bookingid, $date, $slot, $location);
echo"<table>";
echo"<b>Latest Bookings</b>";
echo "<tr><th><b>Date</b></th>
<th><b>Slot</b></th>
<th><b>Location</b></th>
<th><b>Actions</b></th>";
while ($stmt->fetch()) {
if( $date > strtotime("now")) {
echo "<tr>";
echo "<td><p>$date";
echo "<td><p>$slot</td>";
echo "<td><p>$location</td>";
echo "</tr>";
echo "</table>";
}
else{
echo"<table>";
echo"<b>Booking History</b>";
echo "<tr><th><b>Date</b></th>
<th><b>Slot</b></th>
<th><b>Location</b></th>";
while ($stmt->fetch()) {
echo "<tr>";
echo "<td><p>$date";
echo "<td><p>$slot</td>";
echo "<td><p>$location</td>";
echo "</tr>";
echo "</table>";
}
}
}
Change $date > strtotime("now") to this strtotime($date) > strtotime("now"), I hope it will work
Related
I have a problem with updating value with PHP, it can get the data that I input but it cannot update it and render it to the read page.
<?php
require_once("session.php");
require_once("included_functions.php");
require_once("database.php");
new_header("VinceT");
$mysqli = Database::dbConnect();
$mysqli->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (($output = message()) !== null) {
echo $output;
}
echo "<h3>Update A Order</h3>";
echo "<div class='row'>";
echo "<label for='left-label' class='left inline'>";
if (isset($_POST["submit"])) {
$stmt = $mysqli->prepare("UPDATE VTCustomer SET CustomerFName=? WHERE CustomerID=?");
$stmt->execute([$_POST["CustomerFName"],$_POST["CustomerID"]]);
$stmt1 = $mysqli->prepare("UPDATE VTCustomer SET CustomerLName=? WHERE CustomerID=?");
$stmt1->execute([$_POST["CustomerLName"],$_POST["CustomerID"]]);
if($stmt) {
$_SESSION["message"] = $_POST["CustomerFName"]." has been updated";
} else {
$_SESSION["message"] = "Error! Could not update ".$_POST["CustomerFName"];
}
redirect("read.php");
} else {
if (isset($_GET["id"]) && $_GET["id"] !== "") {
$stmt = $mysqli->prepare("SELECT OrderID FROM OrderVinceT WHERE OrderID=?");
$stmt->execute([$_GET["id"]]);
if ($stmt) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<h3>Order ".$row["OrderID"]." Information</h3>";
}
echo "<form method='POST' action='update.php'>";
echo "<input type = 'hidden' name = 'OrderID' value = ' ".$row['OrderID']." ' />";
$stmt1 = $mysqli->prepare("SELECT CustomerFName FROM VTCustomer WHERE CustomerID=?");
$stmt1->execute([$_GET["id"]]);
if ($stmt1) {
while ($row1 =$stmt1 -> fetch(PDO::FETCH_ASSOC)) {
echo "<p>Customer First Name: <input type='text' name='CustomerFName' value='".$row1["CustomerFName"]."'></p>";
}
}
$stmt5 = $mysqli->prepare("SELECT CustomerLName FROM VTCustomer NATURAL JOIN OrderVinceT WHERE OrderVinceT.CustomerID=?");
$stmt5->execute([$_GET["id"]]);
if ($stmt5) {
while ($row5 =$stmt5 -> fetch(PDO::FETCH_ASSOC)) {
echo "<p>Customer Last Name: <input type='text' name='CustomerLName' value='".$row5["CustomerLName"]."'></p>";
}
}
echo "<input type='submit' name='submit' value='Update Order' class='tiny round button'/>";
echo "</form>";
echo "<br /><p>«:<a href='read.php'>Back to Main Page</a>";
echo "</label>";
echo "</div>";
} else {
$_SESSION["message"] = "Order could not be found!";
redirect("read.php");
}
}
}
new_footer("VinceT");
Database::dbDisconnect($mysqli);
?>
Do you guys have any idia why I cannot update this? I test queries in the console and it works just fine. The if statement that render out the message still receive the value of the input but it cannot update the database that render out in read.php
New to PDO and I have a PDO connection script which I am requiring at the top but this is what I have to try and just display the database that is made of up 4 employees and their birthdays. Whenever I run it, I get nothing. Am I at least in the right ballpark here?
<?php
require "pdoconnect.php";
try{
$stmt = $conn->prepare("SELECT bid, bname, bday FROM birthday");
$stmt->execute();
# setting the fetch mode
$result = $stmt->fetchAll();
if( ! $result){
print('No Records Found');
}
else{
echo "<table border='1' align='center' cellpadding='5px' cellspacing='2px'>";
//while($row = $stmt->fetch())
echo "<tr><th>Bid</th><th>Name</th><th>Birthdaay</th><th colspan='2'></th></tr>";
foreach($result as $row){
echo "<tr>";
echo "<td>";
echo $row['bid'];
echo "</td>";
echo "<td>";
echo $row['bname'];
echo "</td>";
echo "<td>";
echo $row['bday'];
echo "</td>";
}
echo "</table>";
}
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
apparently i have issue with displaying the image as it only show me the name of the file, is there anyway for it to display on the webpage right away?
Below is my source code along with 2screenshots of my database holding the image and the place where i want it to display at:
<?php
error_reporting(E_ERROR);
include("global.php");
session_start();
$receipt = $_GET['receipt'];
$userid = $_SESSION ['userid'];
if (isset($_SESSION['userid']) == false)
{
header ("Location: login.php");
}
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$stmt = $mysqli->prepare("SELECT receipt, date, time, pick, dropoff, userid, carno, cost, branch, area, image FROM items where receipt=?");
$stmt->bind_param("s", $receipt);
$stmt->execute();
$stmt->bind_result($receipt, $date, $time, $pick, $dropoff, $userid, $carno, $cost, $branch, $area, $image);
while ($stmt->fetch()) {
echo "<table border='1' style='width:40%'>";
echo "<td>";
echo "<b>Receipt ID: $receipt</b>";
echo "<br><br>";
echo "$image";
echo "<br><br>";
echo "<b>Date of Travel: $date</b>";
echo "<br><br>";
echo "<b>Time of Travel: $time</b>";
echo "<br><br>";
echo "<b>Pick Up Location: $pick</b>";
echo "<br><br>";
echo "<b>Drop Off Location: $dropoff</b>";
echo "<br><br>";
echo "<b>Area of DropOff: $area</b>";
echo "<br><br>";
echo "<b>Cost of Trip: $cost</b>";
echo "<br><br>";
echo "<b>User ID (NRIC): $userid</b>";
echo "<br><br>";
echo "<b>Branch of Officer: $branch</b>";
echo "</td>";
}
echo "</table>";
$stmt->close();
$mysqli->close();
?>
Preview:
Use <img> tag as below
echo "<img src=$image>"
Try this:
echo "<img src='$image'>";
Learn about img
Okay I just changed it to $_POST and it's now working. I'm not sure if this is the shortcut method. At least it's working now. You can help me shrink the code if you want to help me. thanks
<?php
$conn = new mysqli('localhost', 'root', 'jared17', 'hbadb')
or die ('Cannot connect to db');
$result = $conn->query("select * from english");
echo "<html>";
echo "<body>";
echo "<form method = POST>";
echo "<select name = 'Students'>";
while ($row = $result->fetch_assoc()) {
$LRN = $row['LRN'];
$Last = $row['Last_Name'];
$First = $row['First_Name'];
$Lvl = $row['Level'];
$Q1 = $row['Q1'];
$Q2 = $row['Q2'];
$Q3 = $row['Q3'];
$Q4 = $row['Q4'];
$Final = $row['FINAL'];
echo '<option value="'.$LRN.'|'.$Last.', '.$First.'|'.$Lvl.'|'.$Q1.'|'.$Q2.'|'.$Q3.'|'.$Q4.'|'. $Final.'">'.$Last.', '.$First.'</option>';
}
echo "</select>";
echo "<input type='submit' name='submit' value='Show'>";
echo "</form>";
$show = $_POST['Students'];
$show_explode = explode('|', $show);
echo "<table><tr><th>LRN</th><th>Name</th><th>Level</th><th>Q1</th><th>Q2</th><th>Q3</th><th>Q4</th><th>Final</th></tr>";
echo "<tr><td>". $show_explode[0]."</td><td>". $show_explode[1]."</td><td>". $show_explode[2]."</td><td>". $show_explode[3]."</td><td>". $show_explode[4]."</td><td>". $show_explode[5]."</td><td>". $show_explode[6]."</td><td>". $show_explode[7]."</td></tr>";
echo "</table>";
echo "</body>";
echo "</html>";
?>
Don't put all the details in the option value like that. Just put the ID in the value.
echo "<select name = 'Students'>";
while ($row = $result->fetch_assoc()) {
$LRN = $row['LRN'];
$Last = $row['Last_Name'];
$First = $row['First_Name'];
echo '<option value="'.$LRN.'">'.$Last.', '.$First.'</option>';
}
echo "</select>";
Then look it up in the database when the form is submitted.
if (isset($_POST['Students'])) {
$lrn = $_POST['Students'];
$stmt = $conn->prepare("SELECT Last_Name, First_Name, Level, Q1, Q2, Q3, Q4, FINAL FROM english WHERE LRN = ?");
$stmt->bind_param('i', $lrn);
$stmt->execute();
$stmt->bind_result($last, $first, $level, $q1, $q2, $q3, $q4, $final);
$stmt->fetch();
echo "<table><tr><th>LRN</th><th>Name</th><th>Level</th><th>Q1</th><th>Q2</th><th>Q3</th><th>Q4</th><th>Final</th></tr>";
echo "<tr><td>$lrn</td><td>$last, $first</td><td>$level</td><td>$q1</td><td>$q2</td><td>$q3</td><td>$q4</td><td>$final</td></tr></table";
}
You can use $foreach for minimum code when deal with Array. Here code goes
if(isset($_POST['submit'])){
// after post a form ur code goes here
$show = $_POST['Students']; $show_explode = explode('|', $show);
echo "<table><tr>
<th>LRN</th>
<th>Name</th>
<th>Level</th>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
<th>Final</th>
</tr>";
echo "<tr>";
foreach($show_explode as $value){
echo "<td>".$value."</td>";
}
echo "</tr></table>
}
Database:
Calendar 1:
Calendar 2:
Calendar 3:
I'm trying to getting both events from the database onto Monday 4th and I'm wondering why I am only getting one event for April and May.
$sql = "SELECT title, contact, contact_email, DAYOFMONTH(start_date)
FROM $caltbl WHERE start_date LIKE '$year-$month%'";
$result = mysql_query($sql)or die(mysql_error());
$row_count = mysql_num_rows($result);
$record = mysql_fetch_array($result);
while ($day_num <= $days_in_month) {
echo "<td width=\"42\" valign=\"top\">
<a href='index.php?day=$day_num-$title-$year'>
$day_num</a><p/>";
if ($day_num == $record['DAYOFMONTH(start_date)']){
echo " ".$record['title']. "<br/>";
} else{
echo "<br /> " . "<br/> ";
}
echo "</td>";
$day_num++;
$day_count++;
EDIT:
while ($day_num <= $days_in_month) {
echo "<td width=\"42\" valign=\"top\"> <a href='index.php?day=$day_num-$title-$year'>$day_num</a><p/>";
if ($day_num == $record['DAYOFMONTH(start_date)']){
while ($event = mysql_fetch_assoc($result)) {
$array[] = $event;
}
print_r($array);
echo " ".$event['title']. "<br/>";
} else{
echo "<br /> " . "<br/> ";
}
echo "</td>";
$day_num++;
$day_count++;
// Make sure we start a new row each week
if ($day_count > 7) {
echo "</tr><tr>";
$day_count = 1;
}
}
Open a blank array:
$arr = array();
while ($event = mysql_fetch_assoc($result)) {
$arr[] = $event;//store all the data in the $arr array
}
Run a foreach loop to to print the event detail:
foreach($arr as $k=>$v){
if($v['DATEOFMONTH(start_date)']==$day_num){
echo ''.$v['title'].'<br/>';
}else{
echo "<br /> " . "<br/> ";
}
}
Hope this may help. demo