-
Posts
76 -
Joined
-
Last visited
Everything posted by MockY
-
Alert: The phpfreaks forum members data appears to have been stolen.
MockY replied to gizmola's topic in Announcements
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? -
Logical/necessary or not, this is still something I want in place
-
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.
-
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.
-
Show running total from text boxes (dynamic amount of boxes)
MockY replied to MockY's topic in Javascript Help
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. -
Show running total from text boxes (dynamic amount of boxes)
MockY posted a topic in Javascript Help
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/ -
How do I print a list of transaction with some of them in sub categories
MockY replied to MockY's topic in PHP Coding Help
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> -
How do I print a list of transaction with some of them in sub categories
MockY replied to MockY's topic in PHP Coding Help
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 -
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.
-
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
-
Thanks you so much. Works perfectly!
-
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.
-
Ajax call accurately sets $_SESSION variable, but page reload does not work
MockY replied to MockY's topic in Javascript Help
Once I put location.reload(); within the if statement in the triggered() function, it all went just fine. -
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']; } ?>
-
strtotime() is interpreted differently on different servers
MockY replied to MockY's topic in PHP Coding Help
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. -
strtotime() is interpreted differently on different servers
MockY replied to MockY's topic in PHP Coding Help
Ahh I see. This convinient bug is one of few bugs I actually liked. I sadly have to stop updating the server until I find a solution to my problem. Now with the bug fixed, my computations does not work out the way I'd like them to, even though I use the last of the month. If I add a month to a date with 31 days and the next day has only 30, the function skips a whole month an returns 2 more months. Example date('Y-m-t', strtotime('2013-05-31 +1month')); Returns 2013-07-31 Expected 2013-06-30 To me, this seems like a bug in itself and they did not fix anything...just placed the bug elsewhere. I mark the thread as solved as you did in fact answer my question, but you are welcome to take a stab at the new issue. EDIT: Seems like the following did the trick: strtotime('last day of 2013-05-31 +1months')) -
strtotime() is interpreted differently on different servers
MockY replied to MockY's topic in PHP Coding Help
Looking at the change log, nothing has happened since 5.3.0 http://php.net/manual/en/function.strtotime.php I need to use this function in order to calculate how many days ahead or in the past of a given date. Like if a specific date is more than 7 days ago, send out a reminder (just as an example). Sometimes is is a string, sometimes just numbers, and at times even both. Some more complex than others. In other words, I rely heavily on strtotime() in order to fetch the accurate time stamp so I can later print it out using date(). -
strtotime() is interpreted differently on different servers
MockY replied to MockY's topic in PHP Coding Help
date_default_timezone_get() reports America/Los_Angeles on both machines. There is no difference in the code between the machines and strtotime() has always been interpreted the same on them both. And specifically setting it (should not be needed as the default is used if missing) before code execution made not difference -
For a reason that I have no idea, my developer machine is treating strtotime() differently than my server. This has not been the case in the past and I just now, this very day, realized this. I don't know whether this has to do with the PHP version running or not, but I need help to figure this out. Again, I have seen the same output on the developer machine as I have on the server for years, and not until now did I notice a difference. To print out the last day of the month, I have used the following code: date('Y-m-d', strtotime('last day')); OUTPUTS: Server: 2013-05-31 Dev. Machine: 2013-05-06 PHP VERSIONS: Server: 5.3.2 Dev. Machine: 5.3.10 Both machines run Ubuntu Linux (10.04 and 12.04 respectivly) Does this have to do with the differences in PHP or something else? I'm now scared to death to upgrade the server as plenty of my applications and scripts rely on this function in order to process dates and time correctly. I can see how the string 'last day' can be interpreted in both ways, but I just chose this as an example. I have plenty of other strings passed to this function that is no longer interpreted "correctly", much less confusing as the string 'last day'.
-
Proper Directory Structure And How To Loop Through It
MockY replied to MockY's topic in PHP Coding Help
akphidelt2007 - Many thanks for the help. This works very nicely, and it would be very easy for any other program to navigate through the structure to quickly find what needs to be found. Gold star for this solution. And having 100 customers per directory is probably sufficient especially after the read from serverfault.com. Side note: I'm using EXT4 or latest Linux kernel (Ubuntu 12.04). With that in mind, why would someone run EXT3 on a modern server OS? Just curious to whether there is an advantage to run EXT3 over EXT4. -
Proper Directory Structure And How To Loop Through It
MockY replied to MockY's topic in PHP Coding Help
Thanks for your time/reply. Interesting way of handling this. However, if I want to future proof this by expecting 1 million customers, that would give me 10,000 subdirectories in that one directory. Like you said, the number will decrease with increased increment, but what if I just want 10, or 20 subdirectories per directory, how would I go about and do this without ending up with a huge amount of subdirectories in one single root? You mentioned do layers if I expect 10s of thousands of customers...could you elaborate further on that please. -
I'm building a software where the user creates various PDF documents (invoices, forms, etc.). I need a way to store these documents properly, and my initial thought is to store all these PDF files in a directory named by the customer number. I also like to future proof this and by allowing growth to more than a million customers, I'm sure I wont reach the limit. But how would I go about to to properly store this? I'm padding every customer number with preceding zeroes, so customer 1 will be 00000001 and customer 405 will be 00000405. But this is where I'm stuck. Should I do /0/00/000/01 and store it there, but if so, what do I do with the 405 customer? As you can tell, I need some guidance. Once I figure this out, how would I go about to properly loop through the folders to see if they are already created, and if not, create it? I played around with this a bit but I end up with way to much code, but I also started in the wrong end. First I need to figure out what directory structure I should use before attempting the code, but what I came up with looks something like this $customer_id = '1002'; $end_directory = str_pad($customer_id, 10, '0', STR_PAD_LEFT); $zeros = 8-(strlen($customer_id)); $base = 'customer_files/'; $structure = ''; for ($i=1; $i<$zeros+1; $i++) { $structure .= str_pad('0', $i, '0', STR_PAD_LEFT) . '/'; if (!is_dir($base . $structure)) { mkdir($base . $structure); } } if (!is_dir($base . $structure . $end_directory)) { mkdir($base . $structure . $end_directory); }
-
Populate Php Session Variable When User Clicks A Checkbox In Form
MockY replied to MockY's topic in Javascript Help
I know AJAX is the way to go, hence me posting here and not elsewhere. However, I need some guidance to how to proceed with this as I find it far from straight forward. -
Grab the input and the check whether it has the values you want or not. Something like this: if (isset($_POST['Submit'])) { $user_name = trim($_POST['username']); if ($username == "") $error = "You must enter a username"; if (!isset($error)) { // submit the form } else { // display the error by echoing out $error wherever you want it on the page } }
-
In a regular form, how would I go about to populate a php session variable with the value of the checkbox the user checked, all without reloading the page? I don't need to error check or anything for this, as I do that once the user submits the form. I just want to add a value to an existing session variable as soon as the user check the box. Any help is greatly appreciated.