Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. You'll want to do a sub-query to get the most recent 15 in order by the ID, then sort the results of that sub query how you want. SELECT * FROM ( SELECT p.id , b.playerID , b.id , s.toggle AS stoggle , o.toggle AS otoggle , p.city , p.school , s.city , s.school , r.opp_city , r.opp_school , o.city , o.school , r.city , r.school , p.grade , p.nameLast FROM a_players_reviews r INNER JOIN a_players p ON CONCAT (r.nameFirst,r.nameLast) = CONCAT (p.nameFirst,p.nameLast) INNER JOIN a_player_bookmark b ON p.id = b.playerID AND '". $userID ."' = b.userID LEFT JOIN a_schools s ON CONCAT(r.city,r.school) = CONCAT(s.city,s.school) LEFT JOIN a_schools o ON CONCAT(r.opp_city,r.opp_school) = CONCAT(o.city,o.school) WHERE b.bookmark > 0 ORDER BY r.id desc LIMIT 15 ) mostRecent ORDER BY mostRecent.grade , mostRecent.nameLast Some additional notes, if you're going to create a WHERE condition using columns from a joined table, you probably want to use INNER JOIN rather than LEFT JOIN unless you're accounting for NULL values. In general you should use INNER JOIN always unless you have specific reason to use a LEFT JOIN. Your p.id = b.playerID and '$userID' = b.userID conditions are duplicated between your join and WHERE clauses, you only need them in one place, and that is the ON clause so remove them from the WHERE. You didn't qualify your bookmark column with a table but I'm assuming it probably belongs to the a_player_bookmark table (if that's wrong this advice may not apply). If that's the case then your b.bookmark > 0 condition effectively means you're INNER JOINing that table since any null values would fail. As such you can just convert that join to INNER JOIN. If you're intentionally looking for players without a bookmark entry (where the join fails) then you need to make that condition part of the ON clause and use a LEFT JOIN.
  2. How do you determine the most recent entries from a_players_reviews? Is there a datetime column to sort by? Do you want just the most recent row for each player, or the most recent 15 even if multiple of them are from the same player? Sample data and desired output would go a long way to describing what you want.
  3. What platform and PHP version are you using? Can you create some minimal example code that can recreate the crash? I tried setting up some code in a way similar to what you suggest (though I'm not sure what exactly you might be doing and may have got it wrong) and had no issues on windows 10/php 7.3.16
  4. Sounds like all you really need is a class on the parent row's <tr> tag that you can target to apply your padding. That is relatively easy to do by just querying for the .ht_nestingParent cells, getting their parent and adding a class. jQuery(function($){ $('.ht_nestingParent').each(function(){ $(this).parent().addClass('nestingParentRow'); }); }); The you could apply padding to the cells of that row to space it out from the previous section with a little CSS .nestingParentRow td { padding-top: 15px; } .nestingParentRow:first-child td { padding-top: 0; }
  5. Use the -s option: mysql -u $user -p -D $db -Nse "select blah"
  6. You need to use parameter binding rather than variable interpolation.
  7. Your query only returns one row, so there is no need for a loop. Just attempt to fetch that one row and see if any results come back. If so, check them. If not, use your default. $results = mysqli_query($con,$query); $row = mysqli_fetch_assoc($results); if ($row && $row['bookmark']){ echo '-'; } else { echo '+'; }
  8. There's two parts to this, so solve one then the other rather than doing both at the same time. First problem is saving your data. Create a function that you can call with your data and it will save it to your database. Use parameters for the function rather than accessing $_POST directly. For example: function bookmark_add($userId, $itemId){ //run INSERT statement } While getting that working, just use a normal form that will submit the data and refresh the page, eg: <?php if ($_SERVER['REQUEST_METHOD']==='POST'){ //Call your function with the data bookmark_add($_POST['userId'], $_POST['itemId']); } ?> <form method="page.php" action=""> <p>ItemID: <input type="text" name="itemId"></p> <p>UserID: <input type="text" name="userId"></p> <p><button type="submit">Save</button></p> </form> Once you have your function working exactly how you want it, then move on to your "without reloading the page problem." To do this without reloading the page, you need to use javascript to submit the values in the background using AJAX/XHR. Grab something like jQuery and use it's .post method to make this super simple. Now you create a javascript function which will gather your form data and submit it to a PHP page which then calls your PHP function to save it. For example: function submitBookmark(){ var postData = { userId: $('#userId').val() , //.... }; $.post('page.php', postData) .then(/* Success handler */) .catch(/* Failure handler */) ; } Finally setup that function to be executed whenever the user clicks your + image.
  9. You don't really need to check the previous row at all, just create a structured array with the job id as the first key and your columns/children as subkeys. $results = []; while($row = $stmt->fetch(PDO::FETCH_BOUND)) { $jobRow = &$results[$job_number]; if (!$jobRow){ //Job hasn't been seen yet so setup the first level. $jobRow = array( 'Job Number' => $job_number, 'LN #' => null, 'Description' => null, 'Qty' => null, 'AS400 Ship Date' => null, 'Date Showed on Report' => null, 'Days to Manufacture' => null, 'Notes' => null, 'Date Shown Completed' => null, 'Actual Ship Date' => null, 'Qty Shipped' => null, '__children' => [] ); } //Add child line items to the children array $jobRow['__children'][] = array( 'LN #' => $line_item, 'Description' => $description, 'Qty' => $qty, 'AS400 Ship Date' => $as400_ship_date, 'Date Showed on Report' => $date_showed_on_report, 'Days to Manufacture' => "5", 'Notes' => $notes, 'Date Shown Completed' => $date_shown_complete, 'Actual Ship Date' => $actual_ship_date, 'Qty Shipped' => $qty_shipped ); } //Output json. array_values to convert from an object map to an array. echo json_encode(array_values($results));
  10. Not really. I still don't see any reason why what you're trying to do would be any different that just reloading the entire page. In any event, if you do want to update just some areas the proper way, as mentioned, is to have your PHP generate the data as a JSON structure and then have your javascript take that and update all the relevant fields. Using .load with fragment identifiers is extremely wasteful and will put a lot of unnecessary burden on your server, potentially leading to issues. You already posted an example of using JSON, so it seems you have figured at least part of it out. What you'd do is just update your success: handler function to do what you need once the json data is received, for example to update the order number you might do: success: function(data){ $('#order-no').text(data.orderNo); } In your PHP code, make sure you output an appropriate content type before the json. Then it will be parsed automatically by jQuery and provided to your callback rather than you having to parse it yourself. header('Content-type: application/json'); echo json_encode($qryResult); exit;
  11. You should only be using one timezone in all your code and storage. UTC works well but pick whatever you want and use it. By using a single timezone and datetime types then most of this problem goes away. Regardless of what the users local timezone is, you store the date and time in your chosen timezone. Then whenever you want to compare to it you also compare the current time in your chosen timezone to that stored date and time. If you want users to view dates and times in their timezone then convert them from your chosen timezone to their timezone just prior to display. If your using generated times then things are pretty easy in general. If your taking user-submitted dates and times, then things can potentially get a little more complex. If you want users to deal with things according to their local time you'll need to convert their input from their timezone to yours before doing and processing. This is just something you need to decide as one of your business rules. You also need to decide if whatever date you pick is inclusive or exclusive. If I were to subscribe on 2020-04-17 @ 5:20, for one year then does my subscription run 2020-04-17 @ 5:20 -> 2021-04-17 @ 5:20? 2020-04-17 @ 0:00 -> 2021-04-17 0:00? 2020-04-17 @ 0:00 -> 2021-04-17 @ 23:59:59? Up to you to decide. If it were me, I'd probably go for for the last option as I think it's the most intuitive and what people would expect. People are not going to remember the exact minute they signed up, and on the scale of a year I wouldn't nit-pick a few hours.
  12. What are you actually trying to accomplish? Your original code makes it look like you're essentially just trying to refresh the current page, but doing it in pieces instead of all at once. Is there a reason you want to do it that way rather than just reload the page on a timer, such as: jQuery(function(){ //Reload the page in 3 seconds setTimeout(function(){ location.reload(); }, 3000); }); You need to explain what your end-goal is better so that you can receive a real solution to whatever the problem is.
  13. The server can't access the camera. Client-side Javascript however potentially can. It requires the user to grant permission though so it's not something you could just do sneakily in the background. So it's entirely possible to tie a click handler to your login button that would request camera access and then snap a photo and upload it.
  14. It's there, you're just looking in the wrong place probably. You have to expand the New menu first, like I said. I also gave you other ways to accomplish the same task. Pick one.
  15. For this, just right-click the desktop and do New -> Shortcut then put the URL in the text box. This will create an internet shortcut that will open in whatever your default browser is. If you want a browser specific shortcut, then you do like I posted above. Alternatively, open the website in your browser then click the icon next to the URL in the address bar and drag it to the desktop and the browser will create a shortcut to the site for you.
  16. If all you want to do is create a shortcut that opens a specific site, just add the URL you want it to open at the end of the target field. You can further customize the icon and such if you want to make it easy to distinguish. I did this on my HTPC for various streaming services. Most of those are just Firefox shortcuts with the URL added at the end and a custom icon.
  17. Using IndexedDB you'd have a fair bit of persistent storage available at your disposal. Easily enough to handle a full day's worth of surveying, probably much longer, unless your doing something that's crazy data intensive like recording video or lots of photos. You could code things to sync data to somewhere online when you do have an internet connection available such as when you connect to WiFi somewhere. You'll have to look into any compatibility issues for these features. I've not used most of them personally, nor do I use iOS so I have no idea what it does and doesn't support. Bottom line is these days you can do quite a bit if you're willing to put the time into researching what is available and how to use it properly.
  18. kicken

    simple file copying

    Why bother removing all the commented stuff before deploying? If it's commented out then it wont run. If you want some extra code to run locally for debugging then rather than constantly comment/uncomment the code make it conditional on something. For example I setup an environment variable on my development systems called DEBUG_SERVER and can test for that in the code to enable extra stuff. Finally if you really need to be doing some sort of processing before deploying, you could look into something like gulp.
  19. There are multiple settings that affect how much data you can POST to a script, which will affect how many uploads you can perform. post_max_size - Limits the total size of the request so all your images combined must be less than this value. upload_max_filesize - Limits the size of individual files. max_file_uploads - Limits how many file inputs can be uploaded. max_input_vars - Limits how many form fields can be submitted in total. post_max_size needs to be at least as large as upload_max_filesize. I usually set it to upload_max_filesize + 1MB, the extra MB allows for overhead and extra form fields. max_input_vars needs to be at least as much as max_file_uploads. It is by default pretty high.
  20. #cart_change_card a :hover That is incorrect. That says 'some element in :hover state that is a child of an A tag which is a child of #cart_change_card' You want to apply the :hover to the A tag itself which means no space. You also still want to target the icon for the animation so you still need to select that. #cart_change_card a:hover .fa-spin-hover That says 'The .fa-spin-hover element which is a child of an A tag in the :hover state, which is a child of #cart_change_card'
  21. Your not sending any of the form data in your ajax request. All your doing is making a request for the home page. You'll can use the $.post method rather than $.ajax and send your form data along as the request body. Something like: var form = $('#contact-form'); form.submit(function(event){ event.preventDefault(); var form_status = $('.form-status').find('.form-status-content'); form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn(); $.post(form.attr('action'), { name: form.find('[name="name"]').val(), email: form.find('[name="email"]').val(), subject: form.find('[name="subject"]').val(), message: form.find('[name="message"]').val() }).then(function(){ form_status.html('<p class="text-success">Thank you for contact us. As early as possible we will contact you</p>').delay(3000).fadeOut(); }); });
  22. You need to show us the code that isn't working. How exactly did you try and combine them?
  23. $_SERVER['REQUEST_METHOD'] is a string value indicating what HTTP verb was used. To check for a POST request then you need to compare to the string "POST" not the $_POST array. if ($_SERVER['REQUEST_METHOD'] === 'POST'){ //... }
  24. Rather than taking your list of zip codes and doing another query, you could just join the users table in your original query. It would make things easier and more efficient. SELECT u.* FROM users u INNER JOIN ( SELECT zip, (3958*3.1415926*sqrt((latitude-?)*(latitude-?) + cos(latitude/57.29578)*cos(?/57.29578)*(longitude-?)*(longitude-?))/180) as distance FROM zip_codes ) zipDistance ON zipDistance.zip = u.ZIPCODE WHERE zipDistance.distance < ? ORDER BY zipDistance.distance If your $zip variable comes from another query that looks up a user-supplied zip code you could handle that with a join also and simplify your parameters. $sql = ' SELECT r.userId, r.firstName, r.lastName FROM ( SELECT u.userId, u.firstName, u.lastName, (3958*3.1415926*sqrt((userZip.latitude-targetZip.latitude)*(userZip.latitude-targetZip.latitude) + cos(userZip.latitude/57.29578)*cos(targetZip.latitude/57.29578)*(userZip.longitude-targetZip.longitude)*(userZip.longitude-targetZip.longitude))/180) as distance FROM users u INNER JOIN zip_codes targetZip ON targetZip.zip = ? INNER JOIN zip_codes userZip ON userZip.zip=u.ZIPCODE ) r WHERE r.distance < ? ORDER BY r.distance '; $zip = '12345'; //User input $radius = 30; $stmt = $this->db->prepare($sql); $stmt->bind_param('sd', $zip, $radius); $stmt->bind_result($userId, $firstName, $lastName); $stmt->execute(); $userList = []; while ($stmt->fetch()){ $userList[] = [$userId, $firstName, $lastName]; }
  25. I missed a comma between zip and the distance calculation in the inner select query. As a result it's parsing it as a function call instead of as separate columns. Add a comma between zip and ( in the inner select.
×
×
  • 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.