i have this code:
<tr><td>Data expirare:</td><td><?=date_chooser("date",date("Y-m-d"),0)?></td></tr>
It is working properly, but at the moment I look from 1920 until 2050 and I want to show me only of certain pending and the next five years.
I assume you are using the date_chooser() algorithm from this SO post: How to jump to anchor on submit - not to top of page or this internet page: http://ideone.com/Ab0cLD
I adapted a small part of the code by adding two variables: $from_year and $to_year. They do now define the range of the years in your drop down. You can the adapt the value of the variables to your needs.
$chooser.="<select name='".$name."year'>";
$from_year = 1950
$to_year = date("Y") + 5
for($i=$from_year;$i<=$to_year;$i++)
{
if($i==$year) $selected='selected';
else $selected='';
$chooser.="<option $selected>$i</option>";
}
Related
I want to show user that he has vaccinated his goat after successfully payment confirmation.
Here is what I tried:
<?php
$treatperiod1=$product_row['treat1'];
$currentDate = date("Y-m-d");
$totalDays = $treatperiod1;
$usedDays = round(abs(strtotime($currentDate)-strtotime($orderdate))/60/60/24);
$remainingDays = $totalDays-$usedDays;
if($remainingDays==0) {
echo "<a target = '_blank' href ='product_addon.php?treatp=$treatperiod1' class='btn btn-success'><i class='fa fa-pencil'></i>Vaccinate Gaoat</a>";
} elseif($remainingDays==$treatperiod1) {
echo 'Vaccinated';
} else {
echo $remainingDays.' Days Left';
}
?>
I have displayed remaining days for vaccination intervals I want to also display 'Vaccinated' if user payment for vaccination is confirmed. $product_row['treat1']; is a column where the number of days for vaccination is specified. order_details is a table for orders with column confirm for confirmed orders.
Goat Vaccination:
Because Goats don't get Autism
Please read how to use PHP DateTime objects because they will make your life a lot easier on this project.
I will rewrite your code and then tell you what the new code does:
//establish DateTime objects.
$currentDate = new DateTime(); //now.
$orderDate = new DateTime($orderdate); //$orderdate format Y-m-d
//Establish how may days since order date and today.
$difference = $orderDate->diff($currentDate);
$usedDays = $difference->days;
/***
Total Period paid for,
in days, integer.
$product_row['treat1'];
***/
$remainingDays = $product_row['treat1'] - $usedDays;
//Returns an integer value of remaining days.
if($remainingDays < 1) {
echo "<a target = '_blank'
href ='product_addon.php?treatp=".$treatperiod1."'>
Vaccinate Goat</a>";
} elseif($remainingDays==$product_row['treat1']) {
//This will only fire if the goat was vaccinated TODAY.
echo 'Vaccinated';
} else {
echo 'Vaccinated:' .$remainingDays.' Days Left';
}
Hopefully with the help of the link above you should be able to see the basics of what I wrote out for you.
Some notes:
Stop making variables that are simply copies of other variables, it's inefficient and confusing.
(Try to) Stop sending data to new PHP pages as GET URL values such as /newpage.php?treatp=".$var.". This is very probably very insecure.
A more specific answer will need a full explanation from you of your MySQL tables, if nessecary please edit your question and add them.
Try and move away from using timestamps and treating timestamp variables as mathematical entities, and use the DateTime object instead.
Really, to determine if a payment is made you should have a payment date value in your database (set when a payment is successful) and simply compare this date to the value of the integer of the number of days payment covers, using the ->diff() method illustrated above.
Further information on Goat Vaccinations
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I can only use one page and have to use PHP and html in order to make a table using a for loop to increment three different columns. The first column is 'Rate' the second is 'Annual Interest' and the third is 'Monthly Interest'
PURPOSE: Practice in writing calculations and loops and in embedding
HTML inside a PHP tag
PROCEDURE: In this lab you will write a php program that will
calculate the annual and monthly interest on a loan. There will be no
HTML page and no form. The program will use a loop to calculate the
annual and monthly interest rate on 50000 dollars for every interest
rate from 1 to 10 ( 1 being 1% APR (annual percentage rate). Format
the results to display dollar signs and two decimal places. Display
all the data in an HTML table (see provided jpeg). The code must have
variables for the interest rate, annual interest and monthly interest
and must define a constant named AMOUNT that will have a value of
50000.
Annual interest on a loan is calculated by multiplying the loan amount
by the annual interest rate (expressed as a decimal – if the annual
Interest rate is 1 percent the formula will multiply 50000 by .01.
Monthly interest can be calculated by dividing the annual interest by
12. Write a program that will calculate the annual and monthly interest for $50,000 at annual rates from 1 to 10 percent in
increments of 1 percent and output the results as a table. You may use
any type of loop you choose.
HINTS: The first few lines in the php tag will declare your
variables. To create a table, you use echo statements and place the
HTML inside of single quotes. For example, this code, inside a php
tag, will create and display a paragraph element:
echo 'Hello World!';
You will need to indicate the start of a table outside your loop. You
will create the first row of the table outside the loop. The rest of
the rows will be created inside of a loop that uses a counter going
from 1 to 10. Inside each iteration the loop you will calculate the
annual and monthly interest on 50000 using the counter, storing the
answers in your variables and displaying the info in a row of the
table. The ending tag for the table will be after the loop.
Provide a CSS file that will at a minimum will format the table.
Yea, it's a class assignment and unfortunately the class only meets once per week and the professor doesn't really specialize in this subject matter, but a recent surge in enrollment has stretched the faculty kinda thin and she's virtually unavailable. We've only had two classes thus far, and I'm still pretty new to PHP.
*************EDIT*************
<!--Indicates page is HTML5 compliant-->
<!DOCTYPE html>
<html>
<head>
<!--Titles the page at the top such as on the browser tab (w/ Chrome)-->
<title>Monthly & Yearly Interest</title>
<!--Pulls the CSS styling from the main.css page-->
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<main>
<p>Yearly and Monthly Interest for $50,000 at Varying Rates</p>
<table border="1">
<tr><td>Rate</td><td>Annual Interest</td><td>Monthly Interest</td></tr>
<?php
$Ammount = 50000;
$Percent = 1;
$Annual= 500;
$Monthly = $Ammount * $Percent/12;
for ($counter = 1; $counter <= 10; $counter++) {
echo "<td>$Percent%</td><td>$$Annual</td><td>$$Monthly</td>";
$Percent++;
$Annual+=500;
//$Monthly = ;
echo "<tr></tr>";
}
?>
</table>
</main>
</body>
</html>
I've updated my code and cleaned it up. Thank you for all the help. I'm still having an issue with this though. I've tried using $Annual = number_format(500,2); and also modified the increment counter below the echo to do likewise, but I can only get the number formatting to appear on the first row. Also having a similar issue with the $Percent value. Technically I need the percent value to be 0.01 for the $Monthly calculation to be correct, but I need the $Percent value to appear as a whole digit in the first column. I'm trying my best to explain this clearly. I have to use a for loop and have to follow the above instructions in order to create this:
When you're doing string concatenation in PHP you need to use . (dot) operator.
echo "<td>"$percent.'%'"</td>";
must be written as
echo "<td>".$percent."%</td>"; or echo "<td>$percent%</td>";
also for loop consists of 3 part
for (init counter; test counter; increment counter) {
code to be executed;
}
if you want only test counter, you can use it as
for (;$percent <= 10;) {
echo "<td>$percent%</td>";
$percent++
}
or
for ($percent = 1 ; $percent <= 10; $percent++) {
echo "<td>$percent%</td>";
}
HTML table roughly consists of 3 parts
<table>
<tr>
<td>
</td>
<tr>
</table>
You have missed the <tr>
the syntax should look like
<table border="1">
<?php
$percent = 1;
for($percent = 1; $percent < 10; $percent++)
{
echo "<tr><td> $percent % </td></tr>";
}
?>
</table>
or if u want to use your
for ($percent <= 10) {
echo "<td>"$percent.'%'"</td>";
$percent++;
}
use while instead
<?php
$percent = 1;
while($percent <= 10)
{
echo "<tr><td> $percent % </td></tr>";
$percent++;
}
?>
So I have this table filled with a row (we call it $numbers for now) containing numbers greater than 100 000. For example 581 249
I want to echo these values on-screen (using PHP) with a MySql query. Only do I want to divide the returned value by 1000...
The idea is this:
I have made a horizontal bar which is the length of $numbers. But the width of this bar is the value of $numbers in pixels... Basically, it creates a bar with a with of (for example) 581 249 pixels :') ...
This is obviously not the goal. So I have chosen to divide this value by 1k. In this way, the bar fits better on-screen.
How do I implement this in my MySql query?
The echo code for the query is this:
if(isset($_POST['submit'])){
$jaar = $_POST['year'];
echo "<CENTER><h1>".$_POST['year']."</h1></CENTER>";
$result2 = mysql_query("SELECT week, SUM(numbers), SUM(orders) FROM productie WHERE year =" . $year . " GROUP BY week");
while($row=mysql_fetch_array($result2) or die(mysql_error())){
echo "<div class='BarTable'>
<table>
<tr>
<td><div class='BarLabel''>".$row['week']."</div></td>
<td class='BarFull'>
<img src='images/bargraph/month_bar.png' height='12' alt='320' width=".$row['SUM(numbers)']." />
<p>".$row['SUM(numbers)']."</p>
</td>
</tr>
</table>
This while loop goes trough the database, and creates a new bar for every new week found in the database. In this way my result is a nice horizontal bar graph with all the weeks (with the corresponding $numbers) under eachother.
The only problem I'm still facing (as said before), isi that the bars are way too wide. Now I want to decrease the size, but still keep the entered value (since the value of $numbers is displayed behind the bar).
How to divide this value by 1000?
Without mentioning that you should be using PDO or mysqli for new projects, I think what you're looking for is this:
SELECT week, ROUND(SUM(numbers)/1000) as thousandths, SUM(orders) ...
And then access it in your array with $row['thousandths']
So, I am trying to modify a piece of code that I have, it is a calendar that is used for taking reservations. I am posting events on the calendar that users will be able to book by clicking on the link on any given day. It currently allows me to only post 2 events for booking, on any given day. These 2 cannot be at the exact same time. I want to change that, I need it to be able to post multiple spots available at the exact same time. For example, if it is a martial arts class and there are 10 open spots, it should show 10 spots available at the same time of day... You get the point...
I believe this is what is preventing me from achieving that, but im not certain...
Any help is much appreciated. Thanks is advance.
<script>
<?php
if($numslots>0) {
?>
alert('<?php echo $numslots; ?> slots added');
<?php
} else if($numslots == -1) {
?>
alert('Days selected are holidays. Cannot make these changes');
<?php
} else {
?>
alert('Duplicate slots. Cannot make these changes');
<?php
}
?>
document.location.href="calendar_manage.php?calendar_id=<?php echo $_GET["calendar_id"]; ?>&ref=slots";
</script>
In your example, where you have ten slots available for one time, you need to populate a new variable.. lets call it $available_slots.. you need to populate this with the number of slots, in this case ten. So you would end up with ...
$available_slots = 10;
if($numslots<$available_slots) {
?>
alert('<?php echo $numslots; ?> slots added');
<?php
} else if($numslots == -1) {
etc...
Notice the first if condition.. we now check if $numslots is less than $available_slots, rather than greater than zero.
I have got a feature on my website called 'View friends' that displays a hidden div containing a users friends. The only problem so far is I would like it so that it would show 7 members on each row for 3 rows so a total of 21 members on each page. I know I will have to round up NumOfMembers/21 giving me the pages needed. I just need some advice in how I should set up the pagination from when thee SQL query gets the total amount of friends. Any ideas?
The SQL-query should use the limit and offset parameters for pagination, depending on the page n you are on, like this:
SELECT .... LIMIT 21 OFFSET n*21
When handling the results, simply use the modulo operator for determining the lines and rows your current result has to be put in:
// where $i is the result number
$row = $i % 7;
$line = $i % 3;
You have 2 options:
First you can load everything from the php in one query and put all users in an array(content), and just display in pages!
content = [];
max = 21;
function handlePaginationClick(page, pagination_container) {
$('#MyContentArea').empty();
for(var i=0;i<max;i++) {
if(null!=content[(page*max)+i]) $('#MyContentArea').append(content[(page*max)+i]);
}
return false;
}
$("#News-Pagination").pagination(content.length, {
items_per_page:max,
callback:handlePaginationClick
});
you can use Jquery Pagination: https://github.com/gbirke/jquery_pagination#readme
for that.
Another approach is still using jquery pagination, but not load everything at once! then you must have same ajax call in the method 'handlePaginationClick' to pull all page information.