I've been to this site several times before for help which I've managed to solve problems encountered in the past but this time I think I'm going to actually have to ask my own question.
I am working on a system in which employees of a small company can put in their appointments they had every week of the month, including the appointments, number of sales and amount of money made from them. I already calculated things like the success percentage and everything.
Now here lies the problem: I need to make it so that the week numbers are automatically calculated rather than just put in 5 weeks a month.(Currently it works like: January 1-5 February 5 - 10 and so forth) And the numbers need to be linked to a page where the user can edit the information of that week.
I already know how to make a page like this too, the only thing I really need help with is finding out how to best put the week numbers in properly. (Security not being really an issue because it runs on an internal web server.)
Here's the table segment of my calendar.php :
<table id='myTable' width="600" border="1" cellspacing="3">
<tr>
<th align="left">
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>"> Prev </a></th>
<th colspan='3' width="200"><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></th>
<th align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>"> Next </a></th></tr>
<?php
echo "<tr align='center'>";
//Rather than a loop, need to get the amount of weeks in each month.
$startingMonthWeekNum = ((($cMonth-1)*5)+1);
$endingMonthWeekNum = ($cMonth*5+1);
echo "<tr><th>Week #</th><th>Afspraken</th><th>Sales</th><th>Omzet</th><th>Conversie %</th></tr>";
for($i = $startingMonthWeekNum; $i < $endingMonthWeekNum; $i++)
{
//Reset variables
$appointments = null;
$sales = null;
$revenue = null;
$conversie = null;
$result = mysqli_query($con, "SELECT * FROM cms_appointments where date_week = $i and date_year = $cYear and id_user = $userId group by date_week");
$sumAppointments = 0;
$sumSales = 0;
$sumRevenue = 0;
while($row = mysqli_fetch_array($result))
{
$weekRow = $row['date_week'];
$appointments = $row['appointments'];
$sales = $row['sales'];
$revenue = $row['revenue'];
$conversie = $appointments > 0 ? ($sales / $appointments)*100 : 0;
}
$sumAppointments += $appointments;
$sumSales += $sales;
$sumRevenue += $revenue;
echo "<tr align='center'>";
echo "<td>$i</td><td>$appointments</td><td>$sales</td><td>$revenue</td><td>$conversie</td>";
echo "</tr>";
}
echo "<tr align='center'><td>Total</td><td>$sumAppointments</td><td>$sumSales</td><td>$sumRevenue</td><td>".($sumAppointments > 0 ? ($sumSales / $sumAppointments)*100 : 0)."</td></tr>";
echo "</tr> </table>";
mysqli_close($con);
?>
I have a small database behind this with the table cms_appointments having all the information in them which are used in this code. The appointments, sales and revenue.
This is the first time I posted a question and if it can be improved in some way, I will try my best to make it easier as this site helped me out greatly in the past, I want to leave this as a well explained first question.