-
Posts
597 -
Joined
-
Last visited
Everything posted by Adamhumbug
-
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
-
It does not correct and actually i am having the same issue again with a similar problem.
-
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>×</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>
-
Yep that might do it. Cant see the woods for the trees! Thanks as always
-
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?
-
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
-
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; }
-
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; }
-
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?
-
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.
-
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.
-
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>
-
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">
-
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?
-
Thanks all for this - opened the door a little for me
- 6 replies
-
- notifications
- php
-
(and 1 more)
Tagged with:
-
I wasnt sure where best to put this question. I have a website that i built locally using mamp, i now have this hosted with 1&1 and its working online. I am trying to continue development locally rather than playing with the live version but when i now try and navigate to it via local host i get the following error: SSL_Error_rx_record_too_long Anyone got any hints?
-
So it was uploading the image and putting it in the correct folder. It was also adding the file name to the person table image column. None of these things are currently happening. I will have a look into that.
-
I have a form that includes uploading a headshot. This is the form handling f ($_SERVER['REQUEST_METHOD']=='POST'){ $fn = $_POST['fname']; $ln = $_POST['lname']; $ad1 = $_POST['ad1']; $ad2 = $_POST['ad2']; $city = $_POST['city']; $post = $_POST['postcode']; $tel = $_POST['phone']; $email = $_POST['email']; $crole = $_POST['comRole']; $OFA = $_POST['OFA']; $playerType = $_POST['playerType']; $team = $_POST['primaryTeam']; $dob = $_POST['dateOfBirth']; if(!empty($_FILES['fileToUpload'])){ $errors= array(); $file_name = $_FILES['personHeadshot']['name']; $file_size =$_FILES['personHeadshot']['size']; $file_tmp =$_FILES['personHeadshot']['tmp_name']; $file_type=$_FILES['personHeadshot']['type']; $file_ext=strtolower(end(explode('.',$_FILES['personHeadshot']['name']))); $newFileName = $fn."-".$ln.".".$file_ext; $extensions= array("jpeg","jpg","png"); if(in_array($file_ext,$extensions)=== false){ $errors[]="extension not allowed, please choose a JPEG or PNG file."; } if($file_size > 2097152){ $errors[]='File size must be smaller than 2 MB'; } if(empty($errors)==true){ move_uploaded_file($file_tmp,"img/people/".$newFileName); echo "Success"; }else{ print_r($errors); } $personHeadshot = $newFileName; } $stmt = $conn->prepare(" INSERT IGNORE INTO person (fname, lname, committee_role_id, player_type_id, team_id, ad1, ad2, city, postcode, mobile, email, on_field_auth_id, image, dob) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) "); $stmt -> bind_param('ssiiissssssiss', $fn, $ln, $crole, $playerType, $team, $ad1, $ad2, $city, $post, $tel, $email, $OFA, $personHeadshot, $dob); $stmt -> execute(); header("location: admin-people-list.php"); } I also have this file <?php $target_dir = "img/people/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?> This was working locally but now i have uploaded it i cannot get it to work. All of the person data gets put into the DB asside from the file name I appreciate you may need more info to help me which i will provide on request
-
I think the issue is that the values going into the array are strings not integers. I used this to solve my problem function existingTags(){ var plta = $('#peopleLinkedToArticle').val() plta = plta.split(',') taggedPeople = plta for (a in taggedPeople ) { taggedPeople[a] = parseInt(taggedPeople[a], 10); } console.log(taggedPeople) }
-
Apologies, this is mis-titled
-
Hi All, I have a function: function existingTags(){ var plta = $('#peopleLinkedToArticle').val() window.taggedPeople = [plta] console.log(taggedPeople) } This console log shows the following which is correct. Array [ "11,2" ] I have a second function that needs to use tagged people function removeTaggedPeople(){ console.log(taggedPeople) var e = event.target $(e).attr('onclick','tagInArticle()') var taggedPerson = $(e).data('id') var i = 0; while (i < window.taggedPeople.length) { if (window.taggedPeople[i] === taggedPerson) { window.taggedPeople.splice(i, 1); } else { ++i; } } console.log(window.taggedPeople) var tp = window.taggedPeople.toString() $('#peopleLinkedToArticle').val(tp) $(e).remove() } The first console log in the second function which runs on a button click also shows Array [ "11,2" ] Ids are not being removed from this array and i cannot figure out why
-
That works sometimes, if it looking to remove 1, it will also remove one of the 1's from 11,
-
Hi All, I have a number of buttons that when clicked, add their id to a hidden input with a comma. I would like the ability to click another button and remove its id from this input. I have the following that works well function removeTaggedPeople(){ var e = event.target var tagButton = $(e); $(e).attr('onclick','tagInArticle()') var taggedPerson = $(e).data('id') var orig = $('#peopleLinkedToArticle').val() var t = new RegExp(taggedPerson, 'g') var newval = orig.replace(t,'') $('#peopleLinkedToArticle').val(newval) $(e).remove() } The issue is that if i have the id "1" and the id "11" in the input and i click the button with id "1" it will remove every instance of the number 1 in the string. I would like it to only remove "1" Im not sure if you need a little more to go on here but thats my predicament. Thanks in advance
-
i went this route in the end and didnt bother with data attributes. function getMoreNews(limit, offset){ $.ajax({ type: 'post', data: {"ajax" : 'one', "offset" : offset, "limit" : limit}, success: function(resp){ offset = offset + 1 limit = limit + 1 $('.moreNews').append(resp + "<div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger mb-3' onclick='getMoreNews(1,"+offset+");' data-limit='1' data-offset="+offset+">-- Load More News --</div>") } }) };
-
Hi All, I have a function that pulls data in php form my db and uses a limit and an offset. This is currently called like this <?=getAllNews(0,1)?> with 0 being the offset and 1 being the limit. The line after this is a button triggering ajax <div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger' data-limit='1' data-offset='1'>-- Load More News --</div> and the ajax $('.loadMoreNewsTrigger').click(function(){ var offset = $(this).data('offset'); var limit = $(this).data('limit'); $.ajax({ type: 'post', data: {"ajax" : 'one', "offset" : offset, "limit" : limit}, success: function(resp){ offset = offset + 1 limit = limit + 1 $('.moreNews').append(resp + "<div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger' data-limit='limit' data-offset='$offset'>-- Load More News --</div>") } }) }); I am trying to increment the data values before appending the new button to the end but im getting tangled up. help is always appreciated