Jump to content

Steve_NI

Members
  • Posts

    25
  • Joined

  • Last visited

Steve_NI's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your help When I try: $today = date('Y-m-d'); $start = date_create($goalDate); $interval = date_diff($start,$today); I get the error : date_diff() expects parameter 2 to be DateTime, string given But when I then make the second parameter a string: $start = date_create($goalDate); $end = date_create($today); $interval = date_diff($start,$end); I get the error: Object of class DateInterval could not be converted to string I'm getting myself very confused all I want is a number of days between the two dates that I could divide by 7 to work out the number of weeks between the them
  2. I followed the examples with my code: $start = date_create($goalDate); $end = date_create($today); $interval = date_diff($goalDate,$today); I still get the same error as before : date_diff() expects parameter 1 to be DateTime The examples seem to use hard coded dates, but mine will depend on what the user inserts and also will differ dependent upon the current date.
  3. I am trying to work the date difference between two dates I have a form that a user completes and in that form they provide an end date. In my php I convert this to a unix date: $stamp = strtotime($_POST['endldate']); $endDate = date('Y-m-d', $stamp); I then want todays date: $today = date('Y-m-d'); I then want to get the difference in days between the two. I have tried $difference = datediff($endDate,$today) But this returns an error = date_diff() expects parameter 1 to be DateTime What i want to do is then divide the difference by 7 to get the number of weeks How do I get around the error?
  4. Thats perfect Barand, once again many thanks for your help.
  5. Sorry, one final issue. I had to change around the code slightly to take into consideration that the balance on the credit card wil be a negative etc So it looks like: Select Sum( (Select SUM(Balance) from account) + (Select sum( (select sum(Balance) from credit_card) + (select sum(-Amount) FROM bills where Date > $today) ) ) ) as Total But if I have a balance on the bank accounts of 742, a balance on credit cards of -948 and bills still to come out before the end of the month at 189.88 the resultant query produces a total of -405.88000000000001. How do I get it rounded down to just the two decimal places?
  6. Thats its sorted now! Cheers Barand, who would have known a space would cause so much chaos (apart from you obviously lol!) Thanks for your help guys.
  7. Many thanks for coming back to me. I have fixed the missing parentheses but when I run the query now I get #1630 - FUNCTION finance_checker.Sum does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual In this case finance_checker is the name of the datavase containing all the tables. Any ideas how can the SUM function not work for a MySQL database?
  8. Following the guidelines I have a the following query Select Sum ((Select SUM(Balance) from account)-(Select sum((select sum(Balance) from credit_card) - (select sum(Amount) FROM bills where Date > 12))) I want to tally up the total users have in their bank accounts(the database will only have one user) so if they have two accounts one with a balance of 1000 and the other with a balance of 500 their total is 1500. From this I want to deduct their credit card balance plus a total of any bills left to be paid before the end of the month. So if its the 12th today and they have a dd for electricity for 50 on the 15th and a dd for gas on the 25th for 100 thats 150, and their current credit card bill is 600, that means (600 +150)= 750. This is taken away from their account total (1500-750) thus our user has 750 to do him the rest of the month. Here is the table structure CREATE TABLE `bills` ( `BillID` int(11) NOT NULL AUTO_INCREMENT, `Payee` varchar(100) NOT NULL, `Amount` double(6,2) NOT NULL, `Accname` varchar(50) NOT NULL, `Date` int(11) NOT NULL, PRIMARY KEY (`BillID`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 CREATE TABLE `account` ( `accID` int(11) NOT NULL AUTO_INCREMENT, `Bankname` varchar(50) NOT NULL, `Accname` varchar(50) NOT NULL, `Sortcode` int(11) NOT NULL, `Accnum` varchar( NOT NULL, `Balance` double NOT NULL, `PasswordHint` varchar(100) NOT NULL, `OverdraftLimit` double NOT NULL, PRIMARY KEY (`accID`) ) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=latin1 CREATE TABLE `credit_card` ( `CreditCardID` int(11) NOT NULL AUTO_INCREMENT, `ProviderName` varchar(50) NOT NULL, `AccountNumber` int(11) NOT NULL, `PasswordHint` varchar(50) NOT NULL, `CreditLimit` int(11) NOT NULL, `InterestRate` double NOT NULL, `PaymentDay` int(11) NOT NULL, `Accname` varchar(50) NOT NULL, `Balance` int(11) NOT NULL, PRIMARY KEY (`CreditCardID`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1 On running the query I get #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 But I have no quotes on line 1! I have tried running the two queries individually. So I can total the balances and I can add the bills to the credit card bills its only when I try to put the two together does it fall down. Apologies if this is too long I have tried to stick by the rules in the sticky!!!
  9. Ignore my last post I was being a bit of a tube. Sorted now, many thanks for your help!
  10. Again thanks Barand I have changed the option values in the form to make them integers 1,7,28 & 100 <form action="data.php" method="get"> <select name="days"> <option value="1">One Day</option> <option value="7">Seven Days</option> <option value="28">Twenty Eight days</option> <option value="180">One Hundred and Eighty Days</option> </select> <input type="submit" value="Submit"> </form> And in the data.php form I am running the test you suggest $days = isset($_GET['days']) ? intval($_GET['days']):7; echo "Number of days = ".$days; Each time however it echoes out the days is equal to 0. I cannot understand why it is not getting the value submitted from the dropdown menu. Should days at the very least be 7 if that is what we put the default value to be in the ternary operator?
  11. Thanks Barand Here is my HTML code <html> <head> <title> Dropdown </title> </head> <body> <form action="data.php" method="get"> <select name="days"> <option value="One">1</option> <option value="Seven">7</option> <option value="TwentyEight">28</option> <option value="OneHundredEighty">180</option> </select> <input type="submit" value="Submit"> </form> </body> </html> But when i put the following into php $days = $_GET['days']; I get an undefined index error. Can you see where i have gone wrong?
  12. I have a mysql database that contains account transactions amount, account and Date I want to give the user a dropdown option where they have a number of options over which time frame they can see the data i.e they can see transactions over the last 1, 7, 28 days I know the mysql query I need to write to search the database for each option but how do I link the two together? i.e. the user selects the 7 day option, this runs the mysql query and I can produce a table with that data or if the user selects the 28 day option this runs a different mysql query and I can reproduce a table with that data. Can anyone give me some pointers Many thanks
  13. Ok I have managed to code it so that I can loop through the database and it has given me my drop down box populated with unique references from the database. Here is the code: $server = 'localhost'; $user='root'; $pass=''; $db = 'finance_checker'; $mysqli = mysqli_connect($server, $user, $pass, $db); $query = $mysqli->query("SELECT distinct `catagory` FROM `transactions`"); while($array[]= $query->fetch_object()); array_pop($array); ?> <h3>Payments Made by Catagory</h3> <select name="the_name"> <?php foreach ($array as $option): ?> <option value="<?php echo $option->Transaction; ?>"><?php echo $option -> catagory;?></option> <?php endforeach; ?> </select> <?php $query-> close(); ?> This now gives me a dropdown that looks something like: Food Clothes Entertainment Petrol Now what I would like is for my user to be able to click on one of these dropdown options lets say food and this then will link to a search which will for example "Select `payee`, `amount`, `date` From `transactions` Where `catagory` = Food" and then produce a new table of information of all food transactions ie: Payee Amount Date Tesco 20.45 26/10/2013 Boots 12.32 25/10/2013 How would I go about linking the dropdown options back to the database?
  14. Hi I'm looking for some help. I am looking to query a mysql database and get distinct elements from a particular column and have the result set populate a dropdown box. After that I am looking for the ability of a user to click on one of those drop down options and from that it will produce all rows in the table that have that element in it. I'm new to php but the site I am developing is using PHP. First thing I need to know is that if this is even possible to do and if so would anyone have any tutorials that would guide me? thanks!
×
×
  • 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.