Ok, I am fairly new to the PHP scene so please correct anything I might have done wrong ect. I am trying to do a calender list, which as soon as it get to the day after the due date it hides it from view. I currently have it getting the information that is submitted however not sure how to continue from here to make the overdue items hide? I have attached my code below for feedback also.
<?php
include 'db-connect.php';
$result = mysqli_query($con,"SELECT * FROM tasks");
echo "<table border='0' align='center'>
<tr>
<th>Task Title:</th>
<th>Task Description:</th>
<th>Due Date:</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['task'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['datedue'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
You could do it in your MYSQL query
SELECT * FROM tasks WHERE datedue >= CURDATE()
This would only return the rows that were higher or equal to the current date.
Related
I have a table with each row having a cancel link. I would like to cancel a booking for the specific rows. May I know how to start?
The codes of the table is as below.
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
echo "<table border = 1>
<tr>
<th>Custid</th>
<th>Venue</th>
<th>Firt Name</th>
<th>Date</th>
<th>Time</th>
<th>Menu Type </th>
<th>No.of table </th>
<th>Total price </th>
<th>Amount Paid </th>
<th>Make Payment </th>
<th>Cancel Booking</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['Customer_id']. " </td>";
echo "<td>" . $row['Venue_name']. " </td>";
echo "<td>" . $row['First_name']. "</td>";
echo "<td>" . $row['Date']. "</td>";
echo "<td>" . $row['Time']. "</td>";
echo "<td>" . $row['Menu_type']. "</td>";
echo "<td>" . $row['no_of_table']. "</td>";
echo "<td>" . $row['total_price']. "</td>";
echo "<td>" . $row['total_amt_paid']. "</td>";
echo"<td><a href='Payment.php'>Payment</a></td>";
echo"<td><a href='Cancel.php'>Cancel</a></td>";
echo "</tr>";
}
echo "</table>";
}
You need to pass the Cancel.php script some knowledge of what it should delete, so change
echo "<td><a href='Cancel.php'>Cancel</a></td>";
to
echo '<td>Payment</td>';
And then in the Cancel.php script you should receive that value in the $_GET array
<?php
$Customer_id = $_GET['Customer_id'];
If you want to cancel a specific booking you'll need something specific about each booking, like a booking id for example. If we assume you already have that in your table then you can pass this unique value (specific to the row) to your cancel.php and payment.php pages.
To do this we will use a get request and a query string. This will mean your original line changes from this:
echo "<td><a href='Cancel.php'>Cancel</a></td>";
to this one below. We can add the query string unique to each row like this: (assuming it might be called booking_id)
echo "<td><a href='Cancel.php?booking_id=".$row['booking_id']."'>Cancel</a></td>";
You can now retrieve this value on the Cancel.php page like this:
$booking_id = $_GET['booking_id'];
It's worth reading up about SQL injection and consider adding some cleaning method for your string to avoid this. If you are a little rusty on GET and POST then you can check this explanation out.
I want some information that is stored in my database to be an header in a table.
Basically its got a list of competitors down the side with theirs scores running in rows. Each competitor has their own row. At the top of the table is the name of the event they took part in. I cant manage to make the event name come from the database so got to edit the page each time I add a set of scores.
I have attempted as you will see in the code below;
<?php
require("db_connect.php");
$result = mysql_query("SELECT *, (ct1 + ct2 + ct3 + ct4 + ct5 + ct6) AS results FROM resultsopen WHERE ct='1'");
if(mysql_num_rows($result) == 0) { echo 'No competitors found'; } else {
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" align=\"center\">
<tr align=\"center\">
<td>Competitor</td>
<td>Member No</td>
<td>" . $row['cta'] . "</td>
<td>E2</td>
<td>E3</td>
<td>E4</td>
<td>E5</td>
<td>E6</td>
<td>E7</td>
<td>Overall</td>
<td></td>
</tr>";
$x=1;
while($row = mysql_fetch_array($result))
{
if($x%2): $rowbgcolor = "#FFFFFF"; else: $rowbgcolor = "#EEEEEE"; endif;
echo "<tr align=\"center\" bgcolor=\"" .$rowbgcolor. "\">";
echo "<td>" . $row['competitor'] . "</td>";
echo "<td>" . $row['memberno'] . "</td>";
echo "<td>" . $row['ct1'] . "</td>";
The line in question is <td>" . $row['cta'] . "</td>
The other lines are just text which I manually change each time.
I also know that mysql should be changed to mysqli but I am not confident in the change just yet.
I have a comments/testimonials form which saves data into MySQL database testimonials. Now through admin page I want to edit and enable or disable the comments which should show on my comments page. I don't know how to do this.
$query=mysql_query("SELECT * FROM `testimonials` ORDER BY
`t_id` DESC") or die(mysql_error());
if(!$query) {echo "Error!";} else { echo "Testimonials";}
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name,City</th>
<th>Email</th>
<th>Comment</th>
<th>Enable</th>
<th>Edit</th>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $row['t_id'] . "</td>";
echo "<td>" . $row['t_name'] . "</td>";
echo "<td>" . $row['t_email'] . "</td>";
echo "<td>" . $row['t_message'] . "</td>";
echo "<td>" . $row['enable'] . "</td>";
echo "<td>" . $row['edit'] . "</td>";
echo "</tr>";
}
echo "</table>";
Now I want a checkbox to show where $row['enable'] is and an Edit & Save/Update button where $row['edit'] is. When I click 'edit' button I can edit the fields and save them to Database. When I check the checkbox the value in 'enable' field pertaining to those particular comments in database is updated to 'True' so that those can display on the Testimonials page.
Currently I'm creating just a simple website that I'm fooling around with. Users can add movies to watch, and then can view them later on. What my current problem is, is this.
Sorry for the large image. As you can see its displaying the first result correctly, but the second result gets all skrewy and displays at the top of the screen. My code for displaying the data is:
$result = mysql_query("SELECT * FROM `movies`");
echo "
<table id=\"allTable\" align=\"center\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\">
<tr>
<th>ID</th>
<th>Movie</th>
<th>Genre</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['genre'] . "</td";
echo "</tr><br />";
echo "</table>";
}
Any help would be greatly appreciated!
EDIT Fixed the problem right after I created this. Removed from while loop and put it under. Fixed.
echo "</table>"; should be moved outside of your while($row = mysql_fetch_array($result))
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['genre'] . "</td";
echo "</tr><br />";
}
echo "</table>";
So I'm having trouble figuring out how to show a link to a new page based on ID. I've created a review page of all timecards submitted based on employee. It works fine, but in case the employee wants to review an individual record and change specific things in the record is where i'm having trouble with. Below is a snippit of code i'm using to display the information. Because the timecard has MANY fields in I don't need to waste the whole page showing all the information until the employee actually submits the specific card he wants.
$result = mysql_query("SELECT ID,employee,date FROM tcardsubmit WHERE employee = '$empname");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>EMPLOYEE NAME</th>
<th>DATE</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['employee'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
echo "</table>";
That query shows all I really need the employee to see. What i'd like is for the ID number to carry over to a page called 'review.php' but the ID number carries over with it, then I can just use GET ID and pull all the data based on the ID on the review page. Any suggestions?
make a little change on your table
echo "<table border='1'>
<tr>
<th>ID</th>
<th>EMPLOYEE NAME</th>
<th>DATE</th>
<th>ACTION</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['employee'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>Review</td>";
echo "</tr>";
}
echo "</table>";
In the loop add another column and do
echo '<td>View</td>';
In review.php
$id = (int) $_GET['id'];
And query..
SELECT <fields> FROM tcardsubmit WHERE ID = $id
Make sure to escape id .. I did it by casting to an int, but you can also do mysql_real_escape_string