user_reservation.php
<thead>
<tr>
<th scope="col">Number of Guest</th>
<th scope="col">Type of Service</th>
<th scope="col">Date</th>
<th scope="col">Time</th>
<th scope="col">Status</th>
<th scope="col">Edit</th>
</tr>
</thead>
<tbody>
<?php
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['no_guest']; ?></td>
<td><?php echo $row['type_service']; ?></td>
<td><?php echo $row['datepicker']; ?></td>
<td><?php echo $row['t_time']; ?></td>
<td><?php echo $service['status']; ?></td>
<td> edit </td>
</tr>
<?php
}
?>
</tbody>
</table>
<b>STATUS</b><br>
<?php
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<!--<td><?php //echo $row['datepicker']; ?></td>-->
<?php
$today = date("Y-m-d H:i:s");
$startdate = $row['datepicker'];
$offset = strtotime("+2 day");
$enddate = date($startdate, $offset);
$today_date = new DateTime($today);
$expiry_date = new DateTime($enddate);
$status = ($expiry_date < $today_date) ? 'Expired' : 'Active' ;
$result = $dbs->prepare("UPDATE Customers SET status = :status WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->bindParam(':status', $status);
$result->execute();
?>
<?php
}
?>
This is my whole code on user_reservation. All i wanted on my admin_reservation was to fetch whats inside of my status database . but as you can see i cant still insert the status data in my database
Add a column 'status' in your table 'service_info' using phpMyAdmin for example,
then in your time verification :
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info WHERE id = :id");
$result->bindParam(':id', $_SESSION['id']);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<?php
$today = date("Y-m-d H:i:s");
$startdate = $row['datepicker'];
$offset = strtotime("+2 day");
$enddate = date($startdate, $offset);
$today_date = new DateTime($today);
$expiry_date = new DateTime($enddate);
$status = ($expiry_date < $today_date) ? 'Expired' : 'Active' ;
$result = $dbs->prepare("UPDATE Customers SET status = :status WHERE id = :id");
$result->execute(array(':status'=>$status, ':id'=>$_SESSION['id']));
then in your table, just output the status column :
<tr class="record">
<td><?php echo $customers[$key]['firstname'];?></td>
<td><?php echo $service['no_guest']; ?></td>
<td><?php echo $service['type_service']; ?></td>
<td><?php echo $service['datepicker']; ?></td>
<td><?php echo $service['t_time']; ?></td>
<td><?php echo $service['status']; ?></td>
Related
I have this working.
$queryPR = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'PR')";
I need the total amount of rows calculated for specific date.
I need also to the SUM('pagesat') somehow but I have no idea how.
Find the whole code below.
I am trying to build something simple to show the income and outcome for 3 locations that we have.
<table class="responsive-table">
<thead>
<tr>
<th>Vetura</th>
<th>Targa</th>
<th>Dite</th>
<th>Pagesa</th>
<th>Cmimi Ditore</th>
<th>Vazhdim</th>
<th>Te Tjera</th>
<th>Shpenzime</th>
<th>Komente</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'FR')";
$stmt = $DBcon->prepare( $query );
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td><?php echo $row['vetura']; ?></td>
<td><?php echo $row['targa']; ?></td>
<td><?php echo $row['dite']; ?></td>
<td><?php echo $row['pagesa']; ?>€</td>
<td><?php echo $row['cmimiditore']; ?>€</td>
<td><?php echo $row['vazhdim']; ?>€</td>
<td><?php echo $row['tetjera']; ?>€</td>
<td><?php echo $row['shpenzime']; ?>€</td>
<td><?php echo $row['koment']; ?></td>
</tr>
<?php
$pagesa = $row['pagesa'];
$tetjera = $row['tetjera'];
$vazhdime = $row['vazhdim'];
$shpenzime = $row['shpenzime'];
}?>
</tbody>
</table>
<?php
$totali = ($pagesa + $vazhdime + $tetjera);
$gtotal = ($totali - $shpenzime);
?>
<div class="card grey">
<hgroup class="totalDitorRaport">
<h2>Total</h2>
<h1><?php echo $gtotal; ?>€</h1>
</hgroup>
</div>
try this
get the sum of the row pagesa in the loop
$queryPR = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'PR')";
$stmt = $DBcon->prepare( $query );
$stmt->execute();
$sum = 0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
$sum += $row['pagesa'];
}
echo $sum;
I want to arrange the table head with my table body, so the data fill have a same type, how can i doing it??
The black square is the correct one
This is my code
<table>
$syntax = 'SELECT customer,type, count(type) as num FROM view_detail GROUP BY type ORDER BY customer';
$rows = $config->prepare($syntax);
$rows->execute();
$result = $rows->fetchAll(PDO::FETCH_OBJ);
?>
</tr>
<td>No</td>
<td>Customer</td>
<?php for($x=0;$x<count($result);$x++){ ?>
<td><?php echo $result[$x]->type; ?></td>
<?php } ?>
<td>Total</td>
<?php $no = 1;
$query = 'SELECT customer,type, count(type) as tipe FROM view_detail GROUP BY customer ORDER BY customer';
$baris = $config->prepare($query);
$baris->execute();
$hasil1 = $baris->fetchAll(PDO::FETCH_OBJ);
for($i=0;$i<count($hasil1);$i++){
$sql = 'SELECT * FROM view_detail WHERE customer = "'.$hasil1[$i]->customer.'" ORDER BY customer';
$row = $config->prepare($sql);
$row->execute();
$hasil = $row->fetchAll(PDO::FETCH_OBJ);
?>
<tr>
<td><?php echo $no; $no++;?></td>
<td><?php echo $hasil[$i]->customer; ?></td>
<?php
for($y=0;$y<count($result);$y++){
if($y < count($hasil)){
?>
<td><?php echo $hasil[$y]->type; ?></td>
<?php }else{ ?>
<td>0</td>
<?php } } }?>
</tr>
</table>
Thanks
I want to make it like this
Edit:
Dynatrade -> MFN200, N50Z, and N70
Super Bloom -> N70, MFN100, MFN120, and MFN150
I'm trying to display a table of dates, albums and reviews made by users. The date and review show up with no problem, but at the moment my query is only displaying the first CD Title in the list.
Table 'cdreview' has columns 'CDID', 'userID', 'reviewDate', 'reviewText'.
Table 'cd' has 'CDTitle', so I've used a natural JOIN to link the 2 tables by the CDID, but I can't display the correct CDTitle.
Any help would be extremely grateful.
<?php
require_once 'database_conn.php';
$userid = $_SESSION['userSession'];
$sql = "SELECT * FROM cdreview JOIN cd WHERE '$userid'=cdreview.userID ORDER BY reviewDate ASC";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$row = mysqli_fetch_assoc($result);
$date = $row['reviewDate'];
$album = $row['CDTitle'];
$review = $row['reviewText'];
$cdid = $row['CDID'];
?>
<tr align='center'>
<td><?php echo $date;?></td>
<td><?php echo $album;?></td>
<td><?php echo $review;?></td>
<td><a href="edit_review.php?id=<?php echo $cdid;?>">Edit</td>
<td><a href="album.php?id=<?php echo $cdid;?>">Delete</td>
</tr>
</table>
You have to iterate through results :
while ($row = mysqli_fetch_assoc($result) ){
$date = $row['reviewDate'];
$album = $row['CDTitle'];
$review = $row['reviewText'];
$cdid = $row['CDID'];
// print stuff
}
mysqli_fetch_assoc is returning a result set.
You have to loop through this result set and handle each result separately.
while ($row = mysqli_fetch_assoc($result)) {
$date = $row['reviewDate'];
$album = $row['CDTitle'];
$review = $row['reviewText'];
$cdid = $row['CDID'];
?>
<tr align='center'>
<td><?php echo $date; ?></td>
<td><?php echo $album; ?></td>
<td><?php echo $review; ?></td>
<td><a href="edit_review.php?id=<?php echo $cdid; ?>">Edit</td>
<td><a href="album.php?id=<?php echo $cdid; ?>">Delete</td>
</tr>
<?php
}
Here's my code sir:
<?php
session_start();
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info ORDER BY id DESC");
/*$result->bindParam(':id', $_SESSION['id']);*/
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$result2 = $dbs->prepare("SELECT *FROM customer_info ORDER BY id DESC");
$result2->execute();
for($j=0; $row2 = $result2->fetch();$j++){
?>
<tr class="record">
<td><?php echo $row2['firstname'];?></td>
<td><?php echo $row['no_guest']; ?></td>
<td><?php echo $row['type_service']; ?></td>
<td><?php echo $row['datepicker']; ?></td>
<td><?php echo $row['t_time']; ?></td>
<td> delete </td>
</tr>
<?php
}
}
?>
i didnt use a LEFT JOIN for displaying data's from 2 tables. i just want to do it in my own way . But my problem is it duplicates my data . before i inserted my second query its just 2 data's and now its 4 already. i just cant figure it out where is the duplication occurs.
Someone help me out please . Thanks in Advance.
You display data in second for, which is inside first for. So you get result count of customer_info table length*service_info length results. You should save info in arrays and then use only one for cycle. Eg.:
<?php
session_start();
include 'include/db_config.php';
$services = array();
$customers = array();
$result = $dbs->prepare("SELECT * FROM service_info ORDER BY id DESC");
/*$result->bindParam(':id', $_SESSION['id']);*/
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$services[] = $row;
}
$result2 = $dbs->prepare("SELECT *FROM customer_info ORDER BY id DESC");
$result2->execute();
for($j=0; $row2 = $result2->fetch();$j++){
$customers[] = $row2;
}
foreach($services as $key => $service) {
?>
<tr class="record">
<td><?php echo $customers[$key]['firstname'];?></td>
<td><?php echo $service['no_guest']; ?></td>
<td><?php echo $service['type_service']; ?></td>
<td><?php echo $service['datepicker']; ?></td>
<td><?php echo $service['t_time']; ?></td>
<td> delete </td>
</tr>
<?php
}
?>
Btw, i suggest you use different approach, like joins
In phpMyAdmin I have a simple query:
SELECT * FROM `recent` WHERE datediff(now(), `timestamp`) > 1
BUT when I try to do this in my clear_recent.php:
<?php $result = $conn->query("SELECT * FROM `recent` WHERE datediff(now(), `timestamp`) > 1"); ?>
<?php foreach ($result->fetch_assoc() as $row): ?>
<?php while($row = $result->fetch_assoc()) { ?>
<tr>
<td><?php echo($title = $row["id"]); ?></td>
<td><?php echo($title = $row["pid"]); ?></td>
<td><?php echo($title = $row["user_id"]); ?></td>
<td><?php echo($title = $row["timestamp"]); ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
I get an error:
Invalid argument supplied for foreach() in /database/chron/clear_recent.php
Cannot for the life of my figure out what's wrong!!!! Please help!
You should check if the query returns any row. try the following code.
<?php
$result = $conn->query("SELECT * FROM `recent` WHERE datediff(now(), `timestamp`) > 1");
$rows = $result->fetch_assoc();
//check if some rows available.
if (count($rows) > 0) {
foreach ($rows as $row) {
while ($row = $rows) {
?>
<tr>
<td><?php echo($title = $row["id"]); ?></td>
<td><?php echo($title = $row["pid"]); ?></td>
<td><?php echo($title = $row["user_id"]); ?></td>
<td><?php echo($title = $row["timestamp"]); ?></td>
</tr>
<?php
}
}
}
?>
additional question: why you use while loop under the foreach loop? is it right?
You are getting this error because no rows return from this query.