Jump to content

MockY

Members
  • Posts

    76
  • Joined

  • Last visited

About MockY

  • Birthday June 16

Profile Information

  • Gender
    Male
  • Location
    Sacramento

MockY's Achievements

Member

Member (2/5)

1

Reputation

  1. If you don't know how this happened, how are you going to prevent the same thing in the future. Changing password may be a good practice, but if the same vandal can grab a dump again in a month, what good will that do?
  2. Logical/necessary or not, this is still something I want in place
  3. It is allowed to enter any date, but I want the user to be notified if the date they enter is not a year in the future. 99% of the times, that is what will be entered, but once in a blue moon, a different date is required.
  4. I have two text fields in a form. Both accepts dates. I'd like to check whether the second date provided is exactly one year in the future from the first provided date. I can easily do this in PHP but since I need to do the check once the user leaves the second field, I have to resort to JavaScript, using onblur or something. There are two issues I have. 1. Make sure that the strings provided are indeed dates (I would use strtodate() in PHP for this) 2. Regardless of month provided, making sure that the second date is exactly a year in the future of the already provided year I've only captured the values and passed them to Date(). However, it can only handle european style, and if I enter 1981-06-16, the value returned is Jun 15 1981 17:00:00 which is obviously wrong. Here is the simple broken code I have var text1 = document.getElementById("text1"); var start_date = new Date(text1.value); var text2 = document.getElementById("text2"); var end_date = new Date(text2.value); alert(start_date); I need some guidance.
  5. Elegant! Thanks. I will be using your solution. Since the last row is duplicated, if there are any values in the box, this will be duplicated as well. It would be nice if by default the box was empty. But that has little to do with the original question, so this thread is solved. Thanks again.
  6. I'm looking for a solution that adds up a running total from a non predefined amount of text boxes. If the form that I use already have 2 text boxes when the page loads, it works just fine for those boxes. However, my issue appears when I create new text boxes on the fly. Take a look at this Fiddle to get the full picture of what's going on. (In case you use Opera, the sum does not work) http://jsfiddle.net/JtXVR/
  7. I tried both methods and came to the same conclusion: Rebuilding the database from scratch is the only answer. So thank you very much for steering me in the right direction. Using your solution, this is what I came up with. It does what I want but I seriously doubt this is the proper way to go about this. So if you feel like you'd like to share more of your wealth in knowledge, I am all ears. In either case, I'll mark the thread as answered and provide the code I cooked up with based on the database structure you provided. Keep in mind that I did not consider any UI design what so ever in the example. This is just to prove that it worked as intended, and I'll move the adapt the code accordingly when moved to the project. <?php $query = "SELECT t.trans_id, t.trans_date, v.vendor_name FROM transactions t, vendors v WHERE t.vendor_id=v.vendor_id"; $result = mysqli_query($link, $query); if (mysqli_num_rows($result) > 0) { ?> <table> <tr> <th>Date</th> <th>Vendor</th> <th>Category</th> <th>Amount</th> </tr> <?php while($r = mysqli_fetch_assoc($result)) { $trans_id = $r['trans_id']; $trans_date = strtoupper(date('M d', strtotime($r['trans_date']))); $vendor = $r['vendor_name']; $iquery = "SELECT i.item_amount, c.cat_name FROM items i, categories c WHERE c.cat_id=i.category_id AND i.trans_id='$trans_id'"; $iresult = mysqli_query($link, $iquery); if (mysqli_num_rows($iresult) == 1) { // Only one category per transaction $ir = mysqli_fetch_assoc($iresult); ?> <tr> <td><?php echo $trans_date; ?></td> <td><?php echo $vendor; ?></td> <td><?php echo $ir['cat_name']; ?></td> <td><?php echo $ir['item_amount']; ?></td> </tr> <?php } else { // Multiple categories per receipt $total_amount = 0; $transaction_items = array(); while ($ir = mysqli_fetch_array($iresult)) { $total_amount += $ir['item_amount']; $transaction_items[] = array("Category" => $ir['cat_name'], "Amount" => $ir['item_amount']); } ?> <tr> <td><?php echo $trans_date; ?></td> <td><?php echo $vendor; ?></td> <td onclick="toggle_visibility(<?php echo $trans_id; ?>)">Show Details</td> <td><?php echo $total_amount; ?></td> </tr> <tr style="display: none;" class="transaction_details" id="<?php echo $trans_id; ?>"> <td colspan="4"> <div> <?php foreach ($transaction_items as $item) { echo '<div style="float: left; width: 50%;">' . $item['Category'] . '</div>'; echo '<div style="float: left; width: 50%;">' . $item['Amount'] . '</div>'; echo '<div style="clear: both;"></div>'; } ?> </div> </td> </tr> <?php } } ?> </table> <?php } else { echo 'No transactions'; } ?> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <!-- Toggle Transaction details --> <script type="text/javascript"> function toggle_visibility(id) { var e = document.getElementById(id); $(e).toggle(); } </script>
  8. I know my database design leaves plenty to desire, but I do have some normalization going on. But the way I did it a few years back was probably not the greatest of design. But before I go over your suggestions Psycho, I'd like to share the current database design, seeing as I'd much rather leave it somewhat intact to avoid to also completely rebuild the database, as I've done the GUI for the software. But ultimately, I want it to be better so I'm down with a total rebuild as well, but this may shed some light to my thought process (for readability, some items in the tables are not important and therefore omitted). Table: accounts ----------------------------- Id Institution Type AccountDescription CardNumber ------------------------------ Table: main_categories ------------------------------ Id Name ----------------------------- Table: sub_categories ------------------------------ Id Name MainCategoryId ------------------------------ Table: transactions ------------------------------ Id Name MainCategoryId SubCategoryId Date Amount AccountId
  9. PURPOSE Building a budgeting software for personal use where I enter all transactions throughout the month in various accounts. I have used a version I built many years ago, but am looking to enhance it and am now rebuilding it from scratch. I'm almost done with the whole thing but there is one remaining feature that is escaping me. If I go and fill up my car with gas, that transaction is pretty straight forward. On purchase in one category. Gas - $40. But if I go to the grocery store and purchase some beer, a magazine, some tomatoes, and then a soap, then I end up having 4 different categories for the same receipt. Currently, I manually enter 4 different transaction from the same store and the same date. But it is hell to reconsile when the credit card statement lists it as one transaction. I would therefore like to be able to enter multiple categories for one receipt. CURRENT STRUCTURE Take these faux transactions as an example As you see, Nugget is listed twice even though they are from the same receipt, just because there are two categories involved. What I'd like to accomplish is only one line of Nugget with the combined amount listed. I'd like to expand another row underneath to display what categories that results in the total, along with the amounts. WHAT I COOKED UP SO FAR This may totally be off target and not the proper way to go at it, but I'd like to share where my mind took me. I just added a new column for the table (CombinedId) with a default value of NULL, and for the transactions that are "bundled", I add the same number. But when it comes to display these guys, I either come up with something so bloated and to random that it can't be implemented. But this is my thought process is in english: 1. if combined number is found, store it in an array and go to the next transaction. 2. If the combined number changes (either a new transaction with multiple categories or a transaction with only one category), print the contents of the array, empty the array, and print the transaction that triggered the "dump" of the array. This is probably not the way to go, so I need help.
  10. However, this got me thinking about making it a little trickier. I should probably start a new thread, but it so closly related to this question What if I had 2 text fields, and I wanted to fetch the value from the second text box as well. Since I can't use this.value as I'm not fetching value for the active box, what would I use instead. I tried the following, but that did not work. onblur="loadurl('ajax.php?update_record=<?php echo $r['Id']; ?>&net=' + encodeURIComponent(this.value)) + '&comment=' + document.getElementById('comment').value" EDIT: Removing document. made it work
  11. Thanks you so much. Works perfectly!
  12. I do an Ajax call when the user tabs out of a text box using onblur(). It works just fine but I need to pass along variable values that have yet been set. To show what I mean: <input type="text" name="comment[]" onblur="loadurl('ajax.php?update_record=<?php echo $r['Id']; ?>&comment=')" /> The loadurl() function fires the Ajax call and will do it's thing. Problem is, I want the comment variable to have the value of whatever the user types in the box before the user leaves the box. All the script now has to work with is the Id of that specific record. My thought was to add a javascript variable that will get the same value as what the user types using onkeyup or similar but don't know how to do it Any help is greatly appreciated.
  13. Once I put location.reload(); within the if statement in the triggered() function, it all went just fine.
  14. I've been trying to impliement something that is supposed to be easy and straighforward for some time now, but have not succeeded. I am somewhat close now and need a little help with the last step. OBJECTION: Clicking on a link (<a> tag) should execute a php code that sets a $_SESSION variable and displays the result to the user without reloading the page WHAT WORKS: I can click the link (I changed it to a layer instead, but the same rule applies) and it executes the desired php code and properly sets the $_SESSION varaible. However, I have to manually click the reload button on the browser in order for the browser to show the contents of the $_SESSION variable I have tried to add various reloading methods (location.reload() for example) but that does not work. I'll simplify the code; index.php <?php session_start(); ?> <html> <head> <script> function loadurl(dest) { try { xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Something went wrong here"); } xmlhttp.onreadystatechange = triggered; xmlhttp.open("GET", dest); xmlhttp.send("null"); } function triggered() { if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { document.getElementById("ajaxlink").innerHTML = xmlhttp.responseText; } // location.reload(); } </script> </head> <body> <div id="ajaxlink" onclick="loadurl('actions.php?action&q=1')">Click Here</div> <?php echo $_SESSION['person']; ?> </body> </html> actions.php <?php session_start(); if (isset($_GET['action'])) { $q = mysql_real_escape_string(trim($_GET["q"])); $query = "SELECT * FROM user WHERE id='$q' LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $_SESSION['person'] = $row['FirstName'] . ' ' . $row['LastName']; } ?>
  15. Do you see any issues moving forward with my "solution"? I tossed all kinds of dates at it, including leap years, and it always returns what I expect to see. As long as I throw valid dates at it, that is. Using 2012-02-31 (which of cource is not a valid date) would cause it to wrap just like the date(Y-m-t) method did.
×
×
  • 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.