Jump to content

Adamhumbug

Members
  • Posts

    583
  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. If i run this line manually in the console, i get the correct number of rows showing $("[id^='OPRow']").length and if i run my function (without the function part) in console, i get the correct outcome. $("[id^='OPRow']").each(function(index, value){ console.log('each ran') var fn = $("[id^='op_firstname']", this) var ln = $("[id^='op_lastname']", this) var nation = $("[id^='op_nationality']", this) var mobile = $("input[id^='op_t1']", this) var cc = $("select[id^='op_t1d']", this) var role = $("[id^='op_role']", this) var e1 = $("[id^='op_e1']", this) var fnlabel = $("[id$='op_firstname']").text() var lnlabel = $("[id$='op_lastname']").text() var nationlabel = $("[id$='op_nationality']").text() var mobilelabel = $("[id$='op_t1']").text() var cclabel = $("[id$='op_t1d']").text() var rolelabel = $("[id$='op_role']").text() var e1label = $("[id$='op_e1']").text() var row = $("<div class='row'><div class='col-6'><label class='fnlab'></label><div class='input-group mb-3 fnholder'></div></div><div class='col-6'><label class='lnlab'></label><div class='input-group mb-3 lnholder'></div></div></div><div class='row'><div class='col-6'><label class='nationlab'></label><div class='input-group mb-3 ccholder'></div></div><div class='col-6'><label class='mobilelab'></label><div class='input-group mb-3 mobileholder'></div></div></div><div class='row'><div class='col-4'><label class='cclab'></label><div class='input-group mb-3 nationholder'></div></div><div class='col-4'><label class='rolelab'></label><div class='input-group mb-3 roleholder'></div></div><div class='col-4'><label class='e1lab'></label><div class='input-group mb-3 e1holder'></div></div></div>") row.find('.fnholder').append(fn) row.find('.lnholder').append(ln) row.find('.nationholder').append(nation) row.find('.mobileholder').append(mobile) row.find('.ccholder').append(cc) row.find('.roleholder').append(role) row.find('.e1holder').append(e1) row.find('.fnlab').append(fnlabel) row.find('.lnlab').append(lnlabel) row.find('.nationlab').append(nationlabel) row.find('.mobilelab').append(mobilelabel) row.find('.cclab').append(cclabel) row.find('.rolelab').append(rolelabel) row.find('.e1lab').append(e1label) $('.content').append(row) $('.batchrequest input').addClass('form-control') $('.batchrequest select').addClass('custom-select') })
  2. Just to add some more clarification here. The new line is created with AJAX and i have called my function bootRow() at the end of the AJAX which i can see running in the console logs. What is not happening is the second log inside the each function suggesting that the each function is not finding the id when i can see it several times when inspecting the code and can see several of these lines on the screen. The $("[id^='OPRow']").length that i have always returns 0
  3. Perfect, thanks so much, that really helped. Has led me into another issue however (another thread). Unrelated to this answer which is perfect.
  4. Hi, I have a form to collect personal data, fn, ln, email etc. There is a button that creates a new blank line for you to fill out with another persons data. I am wanting to turn this form into a nice bootstrap layout (i have that bit sorted). This worked in my testing environment when i copied some html over (not created from the button). When you click the button you get a line like this. <tr id="OPRow605b06bd13161" class=""> <td class="BRFOPRowPhotoPreviewCell"> <input type="hidden" name="OPID605b06bd13161" id="OPID605b06bd13161" value="New"> </td> <td> <input type="text" size="20" name="op_firstname605b06bd13161" id="op_firstname605b06bd13161" style="" value=""> </td> <td> <input type="text" size="20" name="op_lastname605b06bd13161" id="op_lastname605b06bd13161" style="" value=""> </td> <td> <select name="op_nationality605b06bd13161" id="op_nationality605b06bd13161" style=""> <option value="" selected="selected">Please Select</option> </select> </td> <td> <input type="text" size="30" name="op_t1605b06bd13161" id="op_t1605b06bd13161" style="" value=""> </td> <td> <select name="op_t1d605b06bd13161" id="op_t1d605b06bd13161" style=""> <option value="" selected="selected">Please Select</option> </select> </td> <td> <input type="text" size="30" name="op_role605b06bd13161" id="op_role605b06bd13161" style="" value=""> </td> <td><input type="text" size="20" name="op_e1605b06bd13161" id="op_e1605b06bd13161" style="" value=""> </td> <td class="BRFOPRowPhotoCell"> <input type="hidden" name="op_photo605b06bd13161" id="op_photo605b06bd13161" value=""> <span onclick="doBRForm('editPhotoFromBatchRequest','605b06bd13161','')" class="IPListMenuItem BRFOPRowPhoto noPhoto"> <span class="BRFOPRowPhotoSpan">Add</span> </span> </td> <td class="BRFRemoveRowCell"> <span class="IPListMenuItem BRFRemoveRow" onclick="BRFRemoveRow('OPRow605b06bd13161')"> <span class="BRFRemoveRowSpan">X</span> </span> </td> </tr> The code that i am running is looking for each iteration of the opening ID and then moves stuff around. This works great in the testing environment but does not find that id when it is run inside the system. function bootRow(){ console.log('boot ran') $("[id^='OPRow']").length $("[id^='OPRow']").each(function(index, value){ console.log('each ran') var fn = $("[id^='op_firstname']", this) var ln = $("[id^='op_lastname']", this) var nation = $("[id^='op_nationality']", this) var mobile = $("input[id^='op_t1']", this) var cc = $("select[id^='op_t1d']", this) var role = $("[id^='op_role']", this) var e1 = $("[id^='op_e1']", this) var fnlabel = $("[id$='op_firstname']").text() var lnlabel = $("[id$='op_lastname']").text() var nationlabel = $("[id$='op_nationality']").text() var mobilelabel = $("[id$='op_t1']").text() var cclabel = $("[id$='op_t1d']").text() var rolelabel = $("[id$='op_role']").text() var e1label = $("[id$='op_e1']").text() var row = $("<div class='row'><div class='col-6'><label class='fnlab'></label><div class='input-group mb-3 fnholder'></div></div><div class='col-6'><label class='lnlab'></label><div class='input-group mb-3 lnholder'></div></div></div><div class='row'><div class='col-6'><label class='nationlab'></label><div class='input-group mb-3 ccholder'></div></div><div class='col-6'><label class='mobilelab'></label><div class='input-group mb-3 mobileholder'></div></div></div><div class='row'><div class='col-4'><label class='cclab'></label><div class='input-group mb-3 nationholder'></div></div><div class='col-4'><label class='rolelab'></label><div class='input-group mb-3 roleholder'></div></div><div class='col-4'><label class='e1lab'></label><div class='input-group mb-3 e1holder'></div></div></div>") row.find('.fnholder').append(fn) row.find('.lnholder').append(ln) row.find('.nationholder').append(nation) row.find('.mobileholder').append(mobile) row.find('.ccholder').append(cc) row.find('.roleholder').append(role) row.find('.e1holder').append(e1) row.find('.fnlab').append(fnlabel) row.find('.lnlab').append(lnlabel) row.find('.nationlab').append(nationlabel) row.find('.mobilelab').append(mobilelabel) row.find('.cclab').append(cclabel) row.find('.rolelab').append(rolelabel) row.find('.e1lab').append(e1label) $('.content').append(row) $('.batchrequest input').addClass('form-control') $('.batchrequest select').addClass('custom-select') }) } The button uses jquery to call add the new line so i have also included a call to this function at the end of the Ajax and can confirm that it runs every time the button is pressed. I have console logged the length and it always says 0. I appreciate any pointers you may be able to offer here and i will provide any further information that is required. Thanks in advance.
  5. Something like this might be useful as a point to start with - this is jquery by the way $('#element').on('change', function(){ //do stuff })
  6. I think i have fixed this. Added "as newtime" after the ",time" in your example and that seems to be working when i use "newtime" in the where clause. Thanks so much as every for your continued support!!
  7. This is really useful, thanks so much. As always, one more issue. I am getting an error in the where clause. My where clause is WHERE concat(newdate, ' ', extractvalue(pr_customfields,'/CUSTOMFIELDS/CF[@CFN="TestedTime"]/@CFV')) < NOW() - INTERVAL 36 HOUR; I am getting the error - Unknown column 'pr_customfields' in 'where clause' I think the issue may have something to do with the coma in the concat but i have replaces all of your istances of "time" with the above and "date" with something very similar. The data is stored in xml in the database in the following format hence the method for extraction (maybe there is another way) <?xml version="1.0"?> <CUSTOMFIELDS> <CF CFN="TestedTime" CFV="" CFUID="CF5fb7e3b8ca7d8"/> </CUSTOMFIELDS>
  8. I have one varchar column. Unfortunately i am unable to change the table structure and have to deal with one varchar for date and one varchar for time. An example of the data is below
  9. I have a table that has dates stored in various formats (2021-03-12, 12 Mar 2021). I also have a time stored as a string (07:00) I am wanting to convert the dates in their various formats into one that can be concatonated with the time so that i can find any date/times that are 36 hours old or more. I am pretty stuck with this after trying many different ways and would really appreciate a helping hand on this. Thanks in advance.
  10. Hi, I am trying to move an element with JQ. I am wanting to add the input box to some appended content to a page. My code is below: $("[id^='OPRow']").each(function(index, value){ var fn = $("[id^='op_firstname']", this) console.log(fn) var ln = $("[id^='op_lastname']", this) var nation = $("[id^='op_nationality']", this) var mobile = $("input [id^='op_t1']", this) var cc = $("select [id^='op_t1d']", this) var role = $("[id^='op_role']", this) var e1 = $("select [id^='op_e1']", this) var cc = $("select [id^='op_t1d']", this) $('.content').append("<div class='row'><div class='col-6'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'>"+fn+"</div></div><div class='col-6'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div></div><div class='row'><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div></div><div class='row'><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div><div class='col-4'><label for='basic-url'>Your vanity URL</label><div class='input-group mb-3'><input type='text' class='form-control' id='basic-url'></div></div></div>") }) The output i am getting is [object Object] where the element should be placed. I would appreciate any help with this trying to put the input into the content that gets append to $('.content')
  11. Thanks so much for your reply as always! Will the IFNULL be used in the maths at the bottom of this query? (ptsl_limit - IFNULL(used, 0)
  12. Hi All, I have the following, and when i run it the ifnull() is returning null rather than 0 as shown in the attached. Any help on this would be greatly appreciated. select * from ( SELECT ptsl_ptd_id, SUBSTRING(ptsl_date,1,10) as ptsl_date, ptsl_z_id, z_rfid, ptsl_limit FROM `prs_ptsl` inner join prs_z on ptsl_z_id=z_id where ptsl_ptd_id='7' ) as limits left join ( SELECT pr_ptd_id, za_sdate, za_z_id, za_z_rfid, IFNULL(count(za_pr_id), 0) as used FROM `prs_za` inner join prs_pr on za_pr_id=pr_id where prs_pr.pr_status = 'Approved' or prs_pr.pr_status = 'Submitted' group by za_sdate, za_z_id, za_z_rfid ) as used on limits.ptsl_ptd_id=used.pr_ptd_id and limits.ptsl_date=used.za_sdate and ptsl_z_id=za_z_id where ptsl_date = '2021-06-12' and (ptsl_limit - IFNULL(used, 0) >= 0) limit 100
  13. It does not correct and actually i am having the same issue again with a similar problem.
  14. This is the modal <div class="modal fade" id="editQuoteModal" tabindex="-1"> <div class="modal-dialog modal-xl"> <div class="modal-content"> <div id='editQuoteContent'> <!-- ajax info here --> </div> </div> </div> </div> This is the ajax $('.editQuote').click(function(){ var quoteId = $(this).data("id"); $.ajax({ type: 'post', data: {"ajax" : 'one', "id" : quoteId}, success: function(resp){ $('#editQuoteContent').html(resp) } }) $('#editQuoteModal').modal({ show: true }) }); This is the function function popEditQuoteModal($qId){ include 'includes/dbconn.php'; $stmt = $conn -> prepare(" SELECT q.id, c.id, c.name, j.name, q.name, q.version, q.date_created, qs.status, qs.id FROM quote q LEFT JOIN jobs j on q.job_id = j.id LEFT JOIN client c on j.client_id = c.id LEFT JOIN quote_status qs on q.status = qs.id WHERE q.id = ?"); $stmt -> bind_param('i', $qId); $stmt -> execute(); $stmt -> bind_result($qid, $cid, $cname, $jname, $qname, $version, $dc, $qstat, $qStatId); $out =''; if($stmt -> fetch()){ $out .= "<div class='modal-header'> <h5 class='modal-title'>Update: $qname</h5> <button type='button' class='close' data-dismiss='modal'> <span>&times;</span> </button> </div> <div class='modal-body'> <form class='needs-validation' novalidate method='post'> <div class='form-row'> <div class='col-6 mb-3'> <label for=''>Client Name</label> <select onchange='changeClient()' class='custom-select' required id='selectClient' > <option value='' disabled selected >Select a client</option> ".getClientNamesByID(options, $cid)." </select> <div class='valid-feedback'> Looks good! </div> <div class='invalid-feedback'> Please provide an instance name. </div> </div> <div class='col-6 mb-3'> <label for=''>Job Name</label> <select class='custom-select' id='jobByClient' required name='jobId'> <option value='' disabled>Select a job</option> ".getJobsByClient('options', $cid, $qid)." </select> <div class='valid-feedback'> Looks good! </div> <div class='invalid-feedback'> Please select a job name. </div> </div> </div> <div class='form-row'> <div class='col-6 mb-3'> <label for=''>Quote Name</label> <input type='text' class='form-control' placeholder='Quote Name' value='$qname' required name='quoteName'> <div class='valid-feedback'> Looks good! </div> <div class='invalid-feedback'> Please provide an instance name. </div> </div> <div class='col-3 mb-3'> <label for=''>Version</label> <input type='text' class='form-control' placeholder='Version' value='$version' required name='Version'> <div class='valid-feedback'> Looks good! </div> <div class='invalid-feedback'> Please provide a version. </div> </div> <div class='col-3 mb-3'> <label for=''>Status</label> <select class='custom-select' required name='quoteStatus'> <option value='' disabled selected>Select a quote status</option> ".getQuoteStatusByQSId('options', $qStatId)." </select> <div class='valid-feedback'> Looks good! </div> <div class='invalid-feedback'> Please select a status. </div> </div> </div> <hr> <div class='form-row'> ".getQuotedItemRows($qid)." </div> <button type=submit name='updateQuote' class='btn btn-primary col-2 offset-10'>Update</button> </form> </div>"; } $stmt -> close(); return $out; } This is the button that the modal is called from <div class='dropdown-item pointer editQuote' data-id='$qId'>Edit Quote</div>
  15. Yep that might do it. Cant see the woods for the trees! Thanks as always
  16. I have a user form with a dete button on a dropdown. When you click said button this runs function deleteUser(){ var e = event.target var uid = e.getAttribute("data-id"); console.log(e) console.log(uid) $.ajax({ type: 'post', data: {"ajax" : 'delUser', "id" : uid} }) } which goes into this if(isset($_POST['ajax'])){ switch($_POST['ajax']) { case 'newUserMod': exit(popNewUserModal()); break; case 'userMod': exit(popUserModal($_POST['id'])); break; case 'deleteUser': exit(deleteUser($_POST['id'])); break; } }; which calls this function in another file function deleteUser($id){ include 'includes/dbconn.php'; $stmt = $conn -> prepare("DELETE FROM user WHERE id = ?"); $stmt -> bind_param('i', $id); $stmt -> execute(); header('Location: manage-users'); } I know that i am getting the correct id in the ajax and i can see that the post happens correctly. Any ideas why the users are not being deleted?
  17. Hi All, I have a number of bootstrap dropdowns in a list of users, each use has one. When i click one, it drops down and i populate a modal from one of the buttons. After exiting that modal none of the other dropdowns trigger when clicked. If i reload the page, they work again for one click. I am happy to share code if required, just wanted to know if anyone had run into this? Thanks All
  18. Final Solution function getRentalItems($display){ include 'includes/dbconn.php'; $stmt = $conn -> prepare(' SELECT i.id, item, it.type, price_GBP, price_USD, price_CAD FROM items i LEFT JOIN item_type it on i.type = it.id order by i.type desc '); $stmt -> execute(); $stmt -> bind_result($id, $item, $type, $gbp, $usd, $cad); if($display == 'Options'){ $out = ''; $t = ''; while($stmt -> fetch()){ if ($t == $type){ $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; }else{ $out .= "</optgroup><optgroup label='$type'>"; $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; } $t = $type; } } return $out; }
  19. ok much closer now. Still struggling a bit as you can see function getRentalItems($display){ include 'includes/dbconn.php'; $stmt = $conn -> prepare(' SELECT i.id, item, it.type, price_GBP, price_USD, price_CAD FROM items i LEFT JOIN item_type it on i.type = it.id order by i.type desc '); $stmt -> execute(); $stmt -> bind_result($id, $item, $type, $gbp, $usd, $cad); if($display == 'Options'){ $out = ''; $t = ''; while($stmt -> fetch()){ if ($t == $type){ $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; }else{ $out .= "<optgroup label='$type'>"; $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; } $out .= '</optgroup>'; $t = $type; } } return $out; }
  20. Thanks for that i feel like i am getting close. i have this now function getRentalItems($display){ include 'includes/dbconn.php'; $stmt = $conn -> prepare(' SELECT i.id, item, it.type, price_GBP, price_USD, price_CAD FROM items i LEFT JOIN item_type it on i.type = it.id order by i.type desc '); $stmt -> execute(); $stmt -> bind_result($id, $item, $type, $gbp, $usd, $cad); if($display == 'Options'){ $out = ''; $t = ''; while($stmt -> fetch()){ if ($t == $type){ $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; }else{ $out .= "</optgroup><optgroup label='$type'>"; } $out .= '</optgroup>'; $t = $type; } } return $out; } i am getting 2 headers and 2 results but i feel the logic is correct?
  21. Hi All, I have a table, the column type is an attribute that items in this table share. A simple explanation would be if the field was colour and the items could be one of the colours. I am struggling with a for each loop to get the items out of this table grouped by this value. I am wanting to create a dopdown where the item_type is a header. This is what i have so far which obviously doesnt work: unction getRentalItems($display){ include 'includes/dbconn.php'; $stmt = $conn -> prepare(' SELECT i.id, item, it.type, price_GBP, price_USD, price_CAD FROM items i LEFT JOIN item_type it on i.type = it.id '); $stmt -> execute(); $stmt -> bind_result($id, $item, $type, $gbp, $usd, $cad); if($display == 'Options'){ $out = ''; while($stmt -> fetch()){ $out .= '<optgroup label="$type">'; $out .= "<option data-item='$type' data-GBP='$gbp' data-USD='$usd' data-CAD='$cad' value='$id'>$item</option>"; } } return $out; } I would like the optgroup to be first whenever the type changes. I hope this explanation makes sense - there is an image to show what i mean - the bold text should only appear once per instance.
  22. I immediately saw my issue as soon as i wrote the above. I was including head at the start of the register document rather than just above the html.
  23. Hmm, i am sure i am being very simple here but im not sure i follow. I have updated the code in my head.php to what is in the post above. Most of my other pages include head.php On my register page i have the following error: Register line 73 is: header("location: register.php?user_may_exist"); and head line 14 is the last line of this: <?php if(isset($currentPageTitle)){ $curPage = $currentPageTitle; }else{ $curPage = 'Baldock Town Cricket Club'; }; if(isset($currentPageMeta)){ $desc = "<meta name='description' content='$currentPageMeta'>"; }else{ $desc = "<meta name='description' content='All the latest from Baldock Town CC'>"; }; ?> <!DOCTYPE html>
  24. Do i not still have to include something after the html section? Like follows: <?php if(isset($currentPageTitle)){ $curPage = $currentPageTitle; }else{ $curPage = 'Cricket Club'; }; if(isset($currentPageMeta)){ $desc = "<meta name='description' content='$currentPageMeta'>"; }else{ $desc = "<meta name='description' content='All the latest from CC'>"; }; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> <?= $curPage ?> </title> <?= $desc ?> <meta name="viewport" content="width=device-width, initial-scale=1.0">
  25. Hi All, I am trying to use headers at the end of functions to put the user where they need to be. header("location: register.php?user_may_exist"); I understand how they work and their qwuirks. My issue is, in my head file, i am outputting which causes issues for the headers which come after. I have the following in head.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> <?php if(isset($currentPageTitle)){ echo $currentPageTitle; }else{ echo 'Cricket Club'; }; ?> </title> <?php if(isset($currentPageMeta)){ echo "<meta name='description' content='$currentPageMeta'>"; }else{ echo "<meta name='description' content='All the latest from CC'>"; }; ?> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> Is there a better way for me to achieve this?
×
×
  • 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.