Jump to content

imgrooot

Members
  • Posts

    383
  • Joined

  • Last visited

  • Days Won

    1

Community Answers

  1. imgrooot's post in Is there a better way to do php ajax live search from the database? was marked as the answer   
    Alright so I figured it out. Based on your code, here's my new code. And in the backend-search.php, I had to change $_POST to $_GET. Now it works great. Thanks so much.
    <script type='text/javascript'> $().ready(function() { $('#display-cities').hide(); $("#city-box").keyup(function() { var term = $(this).val(); $.get("snippets/backend-search.php", {"term":term}, function(resp) { $("#display-cities").html("").show(); $.each(resp, function(k,v) { var citydata = '<div class="output-results"><p class="output-p1">' + v.cityname + '</p><p class="output-p2">' + v.provincename + ', '+ v.countryname + '</p></div>'; var citydata2 = '' + v.cityname + ', ' + v.provincename + ', ' + v.countryname + ''; $("#display-cities").append(citydata); $( ".output-results" ).click(function() { $("#city-box-id").val(val.cityid); $("#city-box").val(citydata2); $("#display-cities").html(citydata).hide(); }); }) }, "JSON" ) }) }) </script>  
  2. imgrooot's post in GROUP BY not working properly when used with multiple joined tables was marked as the answer   
    Actually I found the issue. My query works fine. The issue was that only 1 user in my database matched all three parameters.  Which is  why it was only showing a single result. So it's all good now.
    Having said that if you would like to modify my query to show your example, that'd be great.
  3. imgrooot's post in How do I highlight mysql fetch dates in a datepicker? was marked as the answer   
    I found the mistake. All I had to do was to add a "," after the beforeShowday to separate it from the onSelect function. You could've just told me this.
    Also I don't even have to create a variable outside the ajax as you previously told me. It works fine without it. 
    Here's the updated code.
    <script> $(document).ready(function() { function formattedDate(d = new Date) { let month = String(d.getMonth() + 1); let day = String(d.getDate()); const year = String(d.getFullYear()); if (month.length < 2) month = '0' + month; if (day.length < 2) day = '0' + day; return `${year}-${month}-${day}`; } $.ajax({ type: "POST", url: 'snippets/adapter-fetch.php', data: {}, dataType: 'json', success: function(highlighted) { $('#datetimepicker1').datepicker({ dateFormat: "yy-mm-dd", multidate: true, beforeShowDay: function(date) { newDate = formattedDate(date); for(let x=0; x < highlighted.length; x++) { console.log(highlighted[x], newDate); if (highlighted[x] === newDate) { return [true, 'Highlighted', '']; // that 3rd index is the tooltip text } } return [true, '']; // default if not a highlight }, onSelect: function () { var getDate = $("#datetimepicker1").val(); $.ajax({ type: "POST", url: "snippets/adapter-set.php", data: { date: getDate }, success: function(data) { // alert(data); }, error: function() { alert("Error."); } }); } }); } }); }); </script>  
  4. imgrooot's post in How would you use SUM twice in a single query from two separate tables? was marked as the answer   
    Holy cow that actually worked. Thanks a million!!!
  5. imgrooot's post in Is there a proper way to do this query? was marked as the answer   
    Based on what you wrote, here is my new query.  Seems to work. Need to do more testing. What you think?
    $get_raised = $db->prepare("SELECT SUM(deposit) AS total, campaigns.campaign_id FROM campaigns LEFT JOIN member_earnings ON campaigns.campaign_id = member_earnings.campaign_id WHERE campaigns.campaign_id > :campaign_id GROUP BY campaigns.campaign_id ORDER BY total DESC"); $get_raised->bindValue(':campaign_id', 0); $get_raised->execute(); $result_raised = $get_raised->fetchAll(PDO::FETCH_ASSOC); if(count($result_raised) > 0) { foreach($result_raised as $row) { $campaign_id = trim($row['campaign_id']); $campaign_raised = trim($row['total']); ?> <div> <?php echo $campaign_id; ?><br> $<?php echo $campaign_raised; ?> </div> <br> <?php } } else { echo 'no'; }
  6. imgrooot's post in How would you join two columns in the same table? was marked as the answer   
    Perfect. That works like a charm. Thank you.
  7. imgrooot's post in Is there a reason why some images won't upload using this script? was marked as the answer   
    I found what the issue was. 
     
    This code in the script has all lowercase extensions.
    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {} I had to also add all the UPPERCASE extensions as well. And it worked.
    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG" && $imageFileType != "GIF") {}
  8. imgrooot's post in A little help with setting up cookies was marked as the answer   
    You are correct. I only have to set the cookie if there is a sponsor parameter. I retrieve the cookie if the parameter is not set. Here is the updated code and it works.
    $get_user = $_GET['sponsor']; if(!empty($get_user)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "sponsor", $get_user, $date_of_expiry); } else if(empty($get_user)) { if(isset($_COOKIE['sponsor'])) { // find the set cookie $user_cookie = $_COOKIE['sponsor']; } } else {}
  9. imgrooot's post in How do you show only 1 random result from foreach loop? was marked as the answer   
    Ah yes the RAND() does the trick.  
     
    Yes my data is trimmed on the input. I guess I don't need to trim it on the output as well.
  10. imgrooot's post in Can I request a member's bank account info through email? was marked as the answer   
    That is one of the methods I am looking into. 
  11. imgrooot's post in Redirecting a www or non-www to https not working? Here's what i have. was marked as the answer   
    So I have FINALLY solved this problem. Someone helped me out.  Instead of the original code I posted, this is the correct code to redirecting to https succesfully.
    RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.yoursite.com [R,L]
  12. imgrooot's post in How do I a retrieve value from this output? was marked as the answer   
    Awesome. That's that i needed. Thanks.
  13. imgrooot's post in What's the proper way to check if a date is empty or not? was marked as the answer   
    Got it. I will keep that in mind. Thanks.
  14. imgrooot's post in Quick question regarding the api I am using. It's giving me syntax error. was marked as the answer   
    Alright so I figured out why it was giving me that error. 
     
    The reason I was getting the above error was because the wallet address I had in the call was EMPTY. It had no transactions sent or received so it was returning the default error.  All I have to do now is set up my own custom error if the wallet is empty.
  15. imgrooot's post in How would you do these calculations? was marked as the answer   
    Alright so I think I have it figured out. It's rather simple.
    $total_amount = 100; // 100 dollars $total_members = 250; // 250 members $total_commission = 60; // 60% commission $get_percent = ($total_commission / 100) * $total_amount; $new_total = $get_percent / $total_members; // $60 / 250 = 0.24 per user. This is what I was missing before. // Since above is based on 60%, I still have 30% and 10% left. Below are these examples. $total_amount = 100; // 100 dollars $total_members = 50; // 50 members for this example, just to vary it up. $total_commission = 30; // 30% commission $get_percent = ($total_commission / 100) * $total_amount; $new_total = $get_percent / $total_members; // $30 / 250 = 0.12 per user. $total_amount = 100; // 100 dollars $total_members = 20; // 20 members for this example, just to vary it up. $total_commission = 10; // 10% commission $get_percent = ($total_commission / 100) * $total_amount; $new_total = $get_percent / $total_members; // $10 / 250 = 0.04 per user.   $60(60%), $30(30%), $10(10%) sum up to $100. No matter how many users are in each percentage pool, it'll always sum up to that exact total.
  16. imgrooot's post in What do you think is the proper way to automatically delete users? was marked as the answer   
    I understand the normal process of registering user and sending them an email link to activate their account.  Unfortunately my process has to be little different. The user is activated with the signup. So no activation email link is required. They have 24 hours to make a payment or else their account is deleted. I'll take your advice to keep their essential data(user's primary info) and delete all other data.
     
    I have never used cron job before but it seems to be exactly what I am looking for.
  17. imgrooot's post in Javascript for loop keepings on looping with errors. was marked as the answer   
    Alright so I've managed to solve the issue. I'm not sure if this is the correct way but it works.
     
    The issue was that if any one of those 3 dates were empty, then I would receiving the looping errors. All 3 dates have to be active.  Since I am retrieving the dates from the database, I simply did an if else to check if each date was empty or not.
     
    Here's the updated code.
    <script> $( document ).ready(function() { //Create object with the list of due dates //The 'name' will correspond to the field ID to populate the results var dueDates = { <?php if($global_payment_due_1 == '0000-00-00 00:00:00') {} else { ?> 'date1':'<?php echo $global_payment_due_1; ?>', <?php } ?> <?php if($global_payment_due_2 == '0000-00-00 00:00:00') {} else { ?> 'date2':'<?php echo $global_payment_due_2; ?>', <?php } ?> <?php if($global_payment_due_3 == '0000-00-00 00:00:00') {} else { ?> 'date3':'<?php echo $global_payment_due_3; ?>', <?php } ?> }; var timer = setInterval(function() { //Instantiate variables var dueDate, distance, days, hours, minutes, seconds, output; //Set flag to repeat function var repeat = false; // Get todays date and time var now = new Date().getTime(); //Iterate through the due dates for (var dueDateId in dueDates) { //Get the due date for this record dueDate = new Date(dueDates[dueDateId]); // Find the distance between now an the due date distance = dueDate - now; // Time calculations for days, hours, minutes and seconds days = Math.floor(distance / (1000 * 60 * 60 * 24)); hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); seconds = Math.floor((distance % (1000 * 60)) / 1000); //Determine the output and populate the corresponding field output = "OVERDUE"; if (distance > 0) { output = days + "d " + hours + "h " + minutes + "m " + seconds + "s"; repeat = true; //If any record is not expired, set flag to repeat } document.getElementById(dueDateId).innerHTML = output; //If flag to repeat is false, clear event if(!repeat) { clearInterval(timer); } } }, 1000); }); </script>
  18. imgrooot's post in A small issue with finding time difference between 2 dates and then combining the difference with new time. was marked as the answer   
    Now that I think about it, I guess your right.
     
    Anyways I have solved the issue already. Here it is.
    // find the time difference between now and the expiry date $expiry_date = '2017-04-20 09:02:23'; $then = new DateTime($expiry_date); $now = new DateTime(); $remaining_days = $then->diff($now)->format("%a"); // I want to add two weeks to the new date. $current = new DateTime(); $two_weeks = new DateInterval('P2W'); $total_date = $current->add($two_weeks)->format('Y-m-d H:i:s'); // current date + 2 weeks + remaining days difference $dateTime = new DateTime($total_date); $new_date = $dateTime->modify('+'.$remaining_days.' days'); echo $new_date->format('Y-m-d H:i:s');
  19. imgrooot's post in I get this gibberish code after I upload an image. What is it and how can I get rid of it? was marked as the answer   
    it's an old image upload code that I copied from a tutorial and then mixed it with my own. The original code actually created 2 images. One original and the other a thumb image. So I removed that thumb code but it looks like there might be some left and that might be causing it.
     
    Yep so this piece of code was causing it. I removed it in all four cases and no more gibbersh code. It's all good now.
    $thumb = imagecreatetruecolor($width, $height); imagegif($thumb); imagecolortransparent($thumb, imagecolorallocatealpha($thumb, 0, 0, 0, 127)); imagealphablending($thumb, false); imagesavealpha($thumb, true); In terms of why I am using transaction for a single query, i didn't realize it till now.  Some of the other pages have multiple queries that require the transaction so naturally I copied the code.  Thanks for pointing that out.
  20. imgrooot's post in How do I access these values using php variables? was marked as the answer   
    That does the trick. It works perfectly now.  Thank you.  I am surprised they didn't show how to get this data in their API.
  21. imgrooot's post in How do I convert php array to individual variables? was marked as the answer   
    Oh wow, it works. That was simple.  Thank you.
  22. imgrooot's post in Php and MySQL database problem with retrieving data with double quotes was marked as the answer   
    Never mind.  I found the solution. When I output the variable, I have to use htmlentities like this htmlentities($variable_output).
  23. imgrooot's post in Quick help with update query was marked as the answer   
    Ah yes.  I did add the return and it now works.
    function getIt($var) { $pos = strpos($var, ' - '); return substr($var, $pos+3); }
  24. imgrooot's post in How do you order by Asc and DESC with decimal numbers in MySQl database? was marked as the answer   
    Yes you're right.  Thanks a bunch.
  25. imgrooot's post in Is there a way to verticle scroll the mobile dropdown menu if it's larger than the screen? was marked as the answer   
    One small edit. Add the height: 100%. It'll fix any y scrolling issue.  Here's the updated code.
    .nav-mobile { display: none; height: 100%; *zoom: 1; position: fixed; width: 100%; overflow-y: scroll; -ms-overflow-y: scroll; -webkit-overflow-scrolling: touch; // mobile safari }
×
×
  • 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.