Jump to content

BGamlin

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BGamlin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. BGamlin

    PHP Dates

    Hey Doug, Thanks for your reply. I have since managed to solve the problem. It has used a bit more code but does the job nicely For anyone else who is having similar problems as me I have attached the code below. for($count = 1; $count <= $_POST['installments'] { list($d, $m, $y) = split("/", $insStart); $unix = mktime(0,0,0,$m,$d,$y); if($_POST['instFreq'] == "month") { $end_date = date("d/m/Y",strtotime("+1 months",$unix)); } if($_POST['instFreq'] == "quaterly") { $end_date = date("d/m/Y",strtotime("+4 months",$unix)); } if($_POST['instFreq'] == "biAnnual") { $end_date = date("d/m/Y",strtotime("+6 months",$unix)); } if($_POST['instFreq'] == "annual") { $end_date = date("d/m/Y",strtotime("+12 months",$unix)); } echo "<tr>"; echo "<td style='text-align:center;'>$count</td>"; echo "<td><input style='border:none; text-align:center' width:100%;' type='text' name='installmentDate[]' value='".$end_date."' /></td>"; echo "<td><input style='border:none; text-align:right' width:100%;' type='text' name='installmentValue[]' value='".number_format($installmentBase,2)."' /></td>"; echo "</tr>"; $insStart = $end_date; $count++; }
  2. BGamlin

    PHP Dates

    Hi, Firstly, I hope this is the correct area for this post. I am basically developing a piece of PHP code that will calculate when money is due in from a customer as part of an installment paying system. This should be fairly simple what I am trying to accomplish but I always seem to have trouble with dates in PHP! Please see below code. for($count = 1; $count <= $_POST['installments'] { $insStart = strtotime("+4 month", mktime($insStart)); echo "<tr>"; echo "<td style='text-align:center;'>$count</td>"; echo "<td><input style='border:none; text-align:center' width:100%;' type='text' name='installmentDate[]' value='".date("d/m/Y", $insStart)."' /></td>"; echo "<td><input style='border:none; text-align:right' width:100%;' type='text' name='installmentValue[]' value='".number_format($installmentBase,2)."' /></td>"; echo "</tr>"; $insStart = date("d/m/Y", $insStart); $count++; } The above is originally getting the value $insStart from a variable earlier on in the code which is assigned from a database table. It is then taking that plain text formatted date (d/m/Y) and converting it to a UNIX stamp to eventually use the strtotime command to add on the designated time (in this case 4 months). The new date is then re-assigned at the bottom of the loop to be used again until the loop is complete. In its current state the first entry of the loop (where the code picks up the table entry) seems to work correctly. However, for the other results the data stays the same as that of the first and no matter what I do I can't make them change. Please Help! Many Thanks, Ben
  3. Hi, I have a system that uses PHP to create a Word Doc as information is extracted from a table using this code: header("Content-type: applicaton/save"); header("Content-Disposition: attachment; filename="FILE NAME".doc"); header("Pragma: no-cache"); header("Expires: 0"); This part of the system I'm trying to implement is working fine. However, what I would ideally like for it to do (and at this point I understand that it sounds a bit pointless) is to save that downloaded file onto a specified folder location on the server directory i.e. to the uploads folder. This will enable all users of the system to then download / view these files as required. I'm not sure whether this is possible or not but and help would be greatly appreciated. Thanks in advance, Ben
  4. sorry about that, I'll try to elaborate. Basically I wanted to have a total at the bottom of the table shown earlier (I have reattached to this post). This should give a total for, for instance, 100% Legal for all type categories. I thought the code should be something like this: $sql = "(SELECT type, SUM(mdInclTerror) as incl_Terror, SUM(legalExpenses) as legal_exp, SUM(el + pl + pol) as liability, SUM(mdInclTerror) as totalInclTerror FROM tblMaster WHERE insurer='F3' GROUP BY type)"; $result = mysql_query($sql) or die("Query Error: " . mysql_error()); //if ($result && mysql_num_rows($result) > 0) { // Start your table echo "<table align='center' cellpadding='10px'>"; echo "<tr>"; echo "<td align='center'><b></b></td>"; echo "<td align='center'><b>100% MD Including Terrorism</b></td>"; echo "<td align='center'><b>100% Liability</b></td>"; echo "<td align='center'><b>100% Legal Expenses</b></td>"; echo "</tr>"; while($row = mysql_fetch_assoc($result)) { $inclTerror= (float) $row["incl_Terror"]; $legal= (float) $row["legal_exp"]; $liability= (float) $row["liability"]; $totalInclTerror= (float) $row["totalInclTerror"]; echo "<tr><td align='right'><b>".$row['type']."</b></td>"; echo "<td align='center'>£".number_format($inclTerror,2)."</td>"; echo "<td align='center'>£".number_format($liability,2)."</td>"; echo "<td align='center'>£".number_format($legal,2)."</td></tr>"; echo "<tr><td></td>"; echo "<td align='center'>£".number_format($totalInclTerror,2)."</td>"; echo "<td align='center'>£</td>"; echo "<td align='center'>£</td>"; echo "</tr>"; } But this shows a column for each type of business so it's effectively just showing me the total for each type. I have attached a 2nd screenshot of this outcome. Is there any way to have a total at the end of the table to calculate everything for the column under all types? [attachment deleted by admin]
  5. Ok, well the code seems to all be working. PLUS i've sorted out the number formatting. I didn't realise it was that simple... I have stumbled across another problem though :S. Is it possible to calculate off the calculated fields that you helped me with earlier? I thought it would be simply like was done before where you put it in the SELECT statement. but as it's not in the table it won't work like that it would seem any ideas? Thanks
  6. Ok, I have added those two lines. But the error it displayed earlier is still the same saying the server may be down for maint etc etc
  7. It doesn't show an error. It just shows a red marker over the line in Dreamweaver. When the page loads it just comes up with a Server Error message saying the server could be down or moved to a different location
  8. Excellent, thanks that has done the job! There seems to be an error on this line: if ($result && mysql_num_rows($result) > 0) { But I don't think it is needed as those fields will be constantly populated when the page opens Thanks very much for your help! Do you know how to set the thousand marker on numbers? as the fields output are monetary values they could really do with proper formatting
  9. I presume it is only getting data from one record because of the >0????? The loop bit I don't understand i'm afraid, could you give me an example that I could adapt please?
  10. Ok, I didn't realise you needed to do that! I only started learning php about 4 days ago... That has got one of the types but still isn't grouping. I have attached an updated screenshot of the outcome. It sums everything but doesn't group on the type... [attachment deleted by admin]
  11. Hi, Thanks for your help. I have edited this file so many times I must have forgot to change some things back. Have made the changes you said but still nothing. Here is the updated Code..... <?php $inclTerror = 0; $liability = 0; //$liability2 = 0; $legal = 0; $result = mysql_query(" SELECT SUM(mdInclTerror) as incl_Terror, SUM(legalExpenses) as legal_exp, SUM(el + pl + pol ) as liability, type FROM tblMaster WHERE insurer='F3' GROUP BY type"); if ($result && mysql_num_rows($result) > 0) { $query_data=mysql_fetch_array($result); $inclTerror= (float) $query_data["incl_Terror"]; $legal= (float) $query_data["legal_exp"]; $liability= (float) $query_data["liability"]; } echo "<table align='center' cellpadding='10px'>"; echo "<tr>"; echo "<td align='center'>Type</td>"; echo "<td align='center'>100% MD Including</td>"; echo "<td align='center'>100% Liability</td>"; echo "<td align='center'>100% Legal Expenses</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='right'>".$type."</td>"; echo "<td align='center'>£".$inclTerror."</td>"; echo "<td align='center'>£".$liability."</td>"; echo "<td align='center'>£".$legal."</td>"; echo "</tr>"; echo "</table>"; ?> Sorry about lack of code tags first time around. I wasn't aware of there being any...
  12. Hi, I'm very new to MySQL and could really do with some help! I am creating a statistics system which should take information from 5 columns on a table and calculate their totals individually. This area of the code seems to be working. Although thousand formatting isn't working. So help with that too would be great! My main problem is that I need the output to group by a field named 'type'. For some reason the code isn't picking up the data in the type column (Refer to screenshot for further information). Also, here is the code I am using: <?php $inclTerror = 0; $liability = 0; //$liability2 = 0; $legal = 0; $result = mysql_query(" SELECT SUM(mdInclTerror) as incl_Terror, SUM(legalExpenses) as legal_exp, SUM(el + pl + pol ) as liability FROM tblMaster WHERE type='HHC' AND insurer='F3' GROUP BY type"); if ($result && mysql_num_rows($result) > 0) { $query_data=mysql_fetch_array($result); $inclTerror= (float) $query_data["incl_Terror"]; $legal= (float) $query_data["legal_exp"]; $liability= (float) $query_data["liability"]; } echo "<table border='1' align='center' cellpadding='10px'>"; echo "<tr>"; echo "<td align='center'>Type</td>"; echo "<td align='center'>100% MD Including</td>"; echo "<td align='center'>100% Liability</td>"; echo "<td align='center'>100% Legal Expenses</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='right'>".$insType."</td>"; echo "<td align='center'>£".$inclTerror."</td>"; echo "<td align='center'>£".$liability."</td>"; echo "<td align='center'>£".$legal."</td>"; echo "</tr>"; echo "</table>"; ?> I cannot see a problem and everyone I have referred the question too can't see a problem either. Hope someone can help me! Thanks In Advance, Ben [attachment deleted by admin]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.