Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by phppup

  1. Still not getting the connection in PHP (although the SQL seems to work in the db) $sql = "SELECT first_name , sum , FORMAT(@balance := @balance + sum, 2) as balance FROM persons JOIN (SELECT @balance:=0) as init WHERE id = 25"; result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { echo "TEST" . $row['id'] ; } }
  2. Shouldn't this give me a result? test = "SELECT first_name , sum , FORMAT(@balance := @balance + sum, 2) as balance FROM persons JOIN (SELECT @balance:=0) as init WHERE id = 25"; echo $test;
  3. I understand. However, what if I wanted to know the balance after Carol made her deposit? Hypothetically, isn't it simpler to print the calculated data result for a given period than to run the computation for each transaction at that point? I appreciate the help and shared knowledge. Thanks.
  4. Currently very simple to get a handle on the approach, id, name, add, sum I've INSERTED 3 or 4 rows with random data. Now I want to access the LAST value for SUM. Afterward, I expected to INSERT the ADD value to the LAST (sum-1) to create a running balance. [There will be no subtractions, although I assume a negative number would thereby reduce the SUM]
  5. I am trying to generate data similar to a running balance for a checkbook. My approach (correct me if there is a better method) is to get the balance from the previous record ID and then add/subtract the new value and create a new total balance. However, I am not havig succes with MAX(id) or last_insert_id -- is one preferable over the other?? if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ $sql = "SELECT MAX(id) FROM persons"; echo "<br /<br />"; echo $sql; Please assist.
  6. Yes, yes, the code. But first, I'd like to try to resolve this with some education. (especial since I've managed to get the basics of the code working). And I'm wondering if I may be creating my web of complications unnecessarily. So here's a question (that may unravel some mystery and resolve my issues): are there a set of BEST PRACTICES for handling images? After I have uploaded several images, I want to resize and watermark them. At first, my thought process was to create separate functions and call them accordingly upload(); resize (); watermark (); Then I wondered whether I was creating unnecessary redundancy and server load. Am I grabbing the image and writing it to my /images_folder and then grabbing it again to resize and overwrite it, then re-grabbing it and watermarking it and re-overwriting it again? Is that creating workload? Is it better to nest the watermarking function within the resizing for a more streamlined flow? Or does that create impracticalities of it's own?
  7. It's always these seemingly simple tasks that become challenges. I got a good handle on how to watermark some photos (thanks to respondents to my previous post) and developed a script that calls a function that uses imagettftext() Essentially, I can upload multiple images and watermark them before they reach their destination folder. Good stuff. Now, I got this crazy idea of watermarking them with a sequence number, so that if I grab 12 images, each will be labeled with it's sequence number (rather than a standard text watermark). I placed $count++ in my script, and then used $count as my $watermark both inside imagettftext and as a variable. It didn't work. The closest I got was after placing $count++ inside a watermark function, but. of course, that merely labeled each photo with a "1" (bc each call of the function was a new iteration. Can someone please offer some direction here. Thanks.
  8. I want to watermark a simple TEXT line on some images (ie: "SAMPLE") I have successfully created a working code and using imagettftext and the PHP manual, I have summized that the coordinates 0,0 will essentially place the beginning of the text at the top left corner of my image. This would remain the same regardless of the image size or shape. Are there coordinates that will consistently designate the lower-right corner? Do the coordinates change for horizontals and verticals; large files and small?
  9. How can I reverse sort from Z to A? Or by last modified?
  10. This has got to be the UGLIEST CODE that you've ever seen, but I'm sure you'll take some conciliatory victory laps in knowing that IT WORKS. I went from the original echo scanDirectoryImages("uploaded"); $directoryList = opendir($directory); while($file = readdir($directoryList)) { if ($file != '.' && $file != '..') { $path = $directory . '/' . $file; to echo scanDirectoryImages("uploads"); // $directoryList = opendir($directory); // no longer necessary to create the handle $directory = "uploads"; //establishes the folder to be located and scanned // while($file = readdir($directoryList)) { // REMOVED as the wrong approach for glob() foreach (glob("$directory/*") as $file) { //OR foreach (glob($directory."/*") as $file) { //BOTH WORK with either QUOTE MARK scheme (is one more correct?) //foreach (glob("$d/*") as $file) { //part of the Learning Process to determine if a variable needed different handling than a hardcoded routing /***** SAMPLE to work with and TEST *****/ //foreach (glob("uploads/*") as $filename) { //echo "$filename size " . filesize($filename) . "<br />"; echo "$file size " . filesize($file) . "<br />"; //PROVED SUCCESS using variable name $file to avoid conflicting names from TESTing to established script if ($file != '.' && $file != '..') { //no longer necessary, but will not interfere. Let's get functional before pretty // $path = $directory . '/' . $file; $path = $file; //the NEW variable $file INCLUDES $directory AND slash; this was easiest solution. //And it worked. //not sure if it better seperated since listing file NAMES would be neater than the ENTIRE PATH //Best way to break it up???? I hope this validates the sincerity that you doubted earlier. Perhaps you can offer a few (or bunches) of tips for better functionality and clean up. PS: I'm still considering a different/more simplistic script and wonder in recursion is beneficial or just stylish. Thanks for the guidance.
  11. I was thrilled to have gotten a recognizable result after tinkering with the script form the manual and using foreach (glob("upload/*.jpg") as $filename) { echo "$filename size " . filesize($filename) . "<br />"; } I have now run both your scripts and gotten the same output which was an array designated listing of the files in the root directory (including the script itself). Now I am still wrestling with replacing the WHILE with a FOREACH. I have found alternate scripts that seem more simplified than this one. Maybe the recursive style is causing me trouble [not even sure if the approach is really favorable] but I would like to meet this challenge successfully.
  12. I've been at it all day, but half (ok, maybe just a third) of what I'm reading may as well be in Chinese. And another third is incorrect samples and misinformation that doesn't even work. That leaves my own ingenuity, and help form you. I tried using the example you provided, as well as visiting the PHP.net page, and was not able to get results. Doesn't the glob() need a reference directory? It's not simply going to automatically search the entire server, is it? At least now I understand why slapping a glob into glace in conjunction with a WHILE seems to blow-up the script and scramble the results to something that destroys the gallery display (most of the time). I understand a good portion of what you told me, but do appreciate the greater enlightenment. At this point I don't even want the answer given to me, but I'm still having trouble with getting a simple result from $globFiles = glob('*'); echo "<pre>" . print_r($globFiles, 1) . "</pre>"; //OR the PHP.net sample foreach (glob("*.txt") as $filename) { echo "$filename size " . filesize($filename) . "\n"; }
  13. I am trying to get THIS code to SORT so I can use it this weekend. I do not have the time now to re-write it or play with testing (for learning purposes). Seeing the actual answer and how it works will likely be very helpful. I can then review the manual and these posts and fine tune and re-write with a more educated approach, but for now, finding a working solution is the priority.
  14. I think the essentials of my code are echo scanDirectoryImages("uploaded"); $directoryList = opendir($directory); while($file = readdir($directoryList)) { if ($file != '.' && $file != '..') { $path = $directory . '/' . $file; Does glob() need to go directly with the "uploaded/*.*" in the first line ECHO? It fails there. Since the $directoryList comes from $directory does it needed to be effective there? on which? On either? The $path contains data from $directory AND $file, but isn't this too far down in the process to intiate glob()?
  15. Yup, I admit it (as if you needed my guilty plea), I never read up on readdir(). It worked in a tutorial and it just kept on working. I will try to get this problem SORTED out (see what I did there? LOL), but please keep in mind that I chose my username intentionally (as I do not work with coffee as readily as you and many others here). You may have chosen your username with equal intent (not entirely sure yet. *wink*)
  16. echo scanDirectoryImages("uploaded"); is ahead of the function that I provided above. It is a recursive function, so it gets called repeatedly inside the script. I have tried echo scanDirectoryImages(glob("uploaded/*.*")); and completely lost the gallery. I understand that nobody wants to write my script for me, and I am trying NOT to and therefore I am making efforts that seem logical to me. I appreciate that, but honestly, I have checked every link provided and many more on my own. I have tried renaming the $path, and nesting the glob() in every area of my script. Ultimately, as previously mentioned, I either get no affect or I lose the gallery entirely. It's not for lack of trying, but we all know that a misplaced slash, comma, or quote will prevent me from obtaining success. Evidently there is something that I am not seeing. Or something i expect to work that isn't. Perhaps the other pertinent question should be, why would the display (that tested well with three images) suddenly sort randomly? I just want these photos to run or order. Or maybe reverse order. But I suppose I should resolve one problem before moving to the next. PS: sometimes seeing the answer creates a cascade that eliminates the need for postings on similar issues because the learning process takes root.
  17. There is no updated code. All my efforts failed by either causing the gallery to display in its arbitrary order. Otherwise, it eliminated the display entirely because the code was faulty. I thought that glob($directory); was the correct utilization of the command either in conjunction with or before assembling the $directoryList. Again, my efforts seem to be missing the mark, so if you have a viable answer, please let me know.
  18. I thought so but I got the same result. I guess I missed re-running the script. Thanks PS: Like i said, CLEARLY one of those weeks.
  19. Do I need to run the function (or a derivative of it) again? Is there a way to clear the exif_read_data($filesname) do that it grabs in fresh?
  20. It's been one of those weeks, yes. I've tried placing global just about everywhere possible. How about a clue, if not the answer?
  21. I don't know. I must be missing something. Even tried W3 and other sample scripts.
  22. I've been plugging glob() EVERYWHERE, but do not seem to be getting a satisfactory result of sorting my images. Am I doing something wrong? Or is a recursive script incapable of sorting? A solution would be wonderful. 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.