Search the Community
Showing results for tags 'mysql date'.
-
I need some help with the following code. I want it to go through the "bom_terms" table in which $money and $timeframe should be found based on the start date and end date comparisons I am having trouble with. Full Transactions code: /* Transactions */ echo "<h2>Transactions - <a href=\"../transactions/add.php?account=$account\">Add</a></h2>"; if($stmt = $mysqli->prepare("SELECT type, amount, reason, repayplan, repaid, transid, date FROM bom_transaction WHERE account = ? ORDER BY id")); { $stmt->bind_param('i', $account); $stmt->execute(); $stmt->store_result(); $count = $stmt->num_rows; $stmt->bind_result($type, $amount, $reason, $repayplan, $repaid, $transid, $date); if ($count == "0") { echo "<i>No transactions were found.</i><br>"; } while ($stmt->fetch()){ if ($type == "0") {$type = ""; $color = "";} if ($type == "1") {$type = "Added"; $color = "green";} if ($type == "2") {$type = "Removed"; $color = "red";} if ($type == "3") {$type = "Repaid"; $color = "";} if ($repayplan == "0") {$repayplan = "No";} if ($repayplan == "1") {$repayplan = "Yes";} if ($repaid == "0") {$repaid = "No";} if ($repaid == "1") {$repaid = "Yes";} $stmt2 = $mysqli->prepare("SELECT money, timeframe FROM bom_terms WHERE account = ? AND startdate <= '2013-01-03 21:00:00' AND enddate >= '2013-02-20 21:00:00'"); $stmt2->bind_param('i', $account); $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($money, $timeframe); $stmt2->fetch(); $stmt2->close(); $date2 = date("M d, Y", strtotime($date)); echo "<font color=\"$color\">$type $$amount</font> $money/$timeframe $reason $repayplan $repaid $date2 <a href=\"../transactions/edit.php?transid=$transid\">Edit</a><br>"; } $stmt->close(); } echo "<br>"; Part of Coding Asking About (From the above): $stmt2 = $mysqli->prepare("SELECT money, timeframe FROM bom_terms WHERE account = ? AND startdate <= '2013-01-03 21:00:00' AND enddate >= '2013-02-31 21:00:00'"); $stmt2->bind_param('i', $account); $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($money, $timeframe); $stmt2->fetch(); $stmt2->close(); What's it's doing: It's making all results from the "bom_terms" table the same when at least 2 of the results should be different (meaning from a different row of the "bom_terms" table). - Right now it is grabbing the last result found from the table. Not sure why however. Some tests/theories I tried made it so it did show a different row, but they were still all shown as the same. Example (what it is doing now): ---Example--- Added $10.00 40.00/Every 2 Weeks No No Jan 31, 2013 Edit Added $90.00 40.00/Every 2 Weeks No No Feb 05, 2013 Edit Added $20.00 40.00/Every 2 Weeks No No Feb 19, 2013 Edit Removed $46.00 40.00/Every 2 Weeks Vengenz Birthday Party/T-Shirts Yes No Feb 22, 2013 Edit Added $100.00 40.00/Every 2 Weeks No No Mar 05, 2013 Edit ---END Example--- NOTE: The 40.00/Every 2 Weeks is the result from the "bom_terms" table. Example (what I want it to do): ---Example--- Added $10.00 20.00/Every Week No No Jan 31, 2013 Edit Added $90.00 20.00/Every Week No No Feb 05, 2013 Edit Added $20.00 20.00/Every Week No No Feb 19, 2013 Edit Removed $46.00 40.00/Every 2 Weeks Vengenz Birthday Party/T-Shirts Yes No Feb 22, 2013 Edit Added $100.00 40.00/Every 2 Weeks No No Mar 05, 2013 Edit ---END Example--- NOTE: The 40.00/Every 2 Weeks and 20.00/Every Week are the results that would be from the "bom_terms" table. I am hoping there is just a simple problem/error I don't see. .. . . Hopefully you can understand what I am asking and having trouble with - I had a hard time trying to come up with a good way to explain it - this is the best way I could come up with.
- 13 replies
-
- mysql date
- before and after
-
(and 3 more)
Tagged with: