Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

1 Neutral

About Adamhumbug

  • Rank
    Advanced Member

Recent Profile Visitors

1,476 profile views
  1. Hi, i have a search box that when searched brings back names of people in the form of a button. This is ajax. When you click a button with names on, the button gets moved with JS. I would like to be able to collect the ids of the butons that are clicked and put them back into the php function that gets them in the first place. Once they have been clicked, they shouldnt appear in the search results. Ajax and JS that moves the button $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() console.log(searchVal) $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); function tagInArticle($pid){ var tagButton = $('.tagInArticle'+$pid) tagButton.appendTo('#taggedInArticleContainer') }; My PHP function to get the results function searchForPeople($searchVal){ $sv1 = $searchVal; $sv2 = $searchVal; $ids = ''; include 'includes/dbconn.php'; $out =""; $stmt = $conn -> prepare(" SELECT fname, lname, id FROM person WHERE id != ? AND (fname LIKE CONCAT('%',?,'%') OR lname LIKE CONCAT('%',?,'%')) "); $stmt -> bind_param('sss', $ids, $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle$pid' onclick='tagInArticle($pid)'>$fn $ln</div>"; } return $out; }
  2. I have a function in JS that i would like to pass 2 variables to. One is an int and one is a string. I am struggling to get the string part right as it needs to be wrapped in quotes. My code is : $out.="<div onclick='newTransactionLine(".$r['id'].",".$r['direction'].")' class='transactionItem btn $class d-block mb-2' data-id='".$r['id']."' >".$r['item']."<br/>£".$r['price']."</div>"; which outputs: <div onclick="newTransactionLine(1,OUT)" class="transactionItem btn btn-primary d-block mb-2" data-id="1">Adult Membership (£85)<br>£85.00</div> When i click the button that gets made, i get a reference error on the word out. I have no doubt it is very simple but i just cannot get this to work for me.
  3. Turns out this did it moneyValues.push(parseInt(transIN[i].getAttribute('value')))
  4. I am creating an array of numbers that i would like to add together and get a sum. JS thinks that these are string and when i try and add one to another, they get appended to the end. This is the code that i have: The second console log gives me 85.00 for example. When the code runs again i end up with 85.0085.00 function financialsReCalc(){ var transIN = document.getElementsByClassName("newTransValue"); console.log(transIN); moneyValues = []; for (i = 0; i < transIN.length; i++) { moneyValues.push(transIN[i].getAttribute('value')) } var moneyvals = moneyValues.reduce(myFunc); function myFunc(total, num) { return total + num; } console.log(moneyvals) } All i am looking to do is add up the numbers in the array
  5. Yes that was the answer. Thanks so much
  6. It is dynamic - you think onClick() on the where the div is created?
  7. I have a modal: My Modal The user should be able to click on the items on the right to add them to the left. The code for the buttons is: <div data-id="1" class="transaction-item btn btn-primary d-block mb-2">Adult Membership (£85)<br>£85.00</div> i have some ajax that is looking for the button press: $('.transaction-item').click(function(){ var itemId = $(this).data("id"); console.log(itemId); $.ajax({ type: 'post', data: {'ajax' : 'three', "id" : itemId}, success: function(resp){ $('#transaction-container').html(resp) } }) }); Then this happens: case 'three': exit(newTransactionItem($conn, $_POST['id'])); break; Then this should build the item to go in function newTransactionItem($conn, $itemId){ include 'includes/dbconn.php'; $stmt = $conn ->prepare(" SELECT item, direction, value FROM transaction_items where id = ? "); $stmt -> bind_param("i", $itemId); $stmt -> execute(); $stmt -> bind_result($item, $dir, $val); $out=""; while($stmt -> fetch()){ if($dir == "IN"){ $class = 'alert-primary'; }else{ $class = 'alert-dark'; } $out.=" <div class='alert $class'> <span class='mr-3'>1 x</span> <span class='font-weight-bold'>$item</span> <span class='ml-3 border-left'>$notes</span> <span class='float-right'>£$val</span> </div> "; } return $out; } Currently, nothing is happening when i click the button with that class. I have a console log in the ajax which is not running. Literally nothing is happening on button click. As always, your help is appreciated.
  8. I worked it out <?php include '../includes/dbconn.php'; if ($_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']; $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 excately 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) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) "); $stmt -> bind_param(ssiiissssssis, $fn, $ln, $crole, $playerType, $team, $ad1, $ad2, $city, $post, $tel, $email, $OFA, $personHeadshot); $stmt -> execute(); header("location: ../admin-people-list.php"); }
  9. HI All, I have a form submission that uploads a photo as well as submitting other data. I would like to change the name of the photo to the id of the person record (created automatically on by the database) then a hyphen, then their first name and lastname. (i am flexible on this). This file name will also need to be submitted into the person record so the photo and the person can be linked. I am struggling with this one - but here is the code i have so far. <?php include 'includes/dbconn.php'; $target_dir = "img/people/"; $target_file = $target_dir . basename($_FILES["personHeadshot"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); if ($_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']; $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) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) "); $stmt -> bind_param(ssiiissssssi, $fn, $ln, $crole, $playerType, $team, $ad1, $ad2, $city, $post, $tel, $email, $OFA); $stmt -> execute(); // Check if image file is a actual image or fake image //photo upload $check = getimagesize($_FILES["personHeadshot"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } //photo upload header("location: ../admin-people-list.php"); } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["personHeadshot"]["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["personHeadshot"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["personHeadshot"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } }
  10. Hi All, I have a prepared statement which give me a bound result $pom If the value is NULL i would like the output to be "EVEN" if it is not null i would like it to equal itself with a poundsign infront. I have the following: $stmt -> bind_result($pom); while($stmt -> fetch()){ $pom = "£{$pom}" ?? "Even"; $out .= "<div>$pom</div>"; } return $out; I have found that whatever the outcome, it is the same on each row. I either get the £ sign or i dont for everything. If i remove the £ completely to the following, it works perfectly. $pom = $pom ?? "Even";
  11. This is the order of the code in the nav.php <?php if($currentPage != 'home'){ echo <<<TEXT <div id="sponsor-bar"> <img src="img/sponsor-bar.png" alt="" style="width:100%;"> </div> TEXT; } ?> <div id="main-nav-bar" class=""> <a class="active" href="index.php">Home</a> <a href="javascript:void(0)">News</a> <a href="javascript:void(0)">Senior Cricket</a> <a href="javascript:void(0)">Junior Cricket</a> <a href="javascript:void(0)">Social Events</a> <a href="players.php">Players</a> <a href="javascript:void(0)">Training</a> <a href="javascript:void(0)">Sponsors</a> <a href="committee.php">Committee</a> </div> sorry this post is bitty
  12. I have uploaded a video of what is happening here https://filebin.net/ur647qv7tqlw62bt
  13. I have the following code that lives in the php file with the navbar html. <script> // When the user scrolls the page, execute myFunction window.onscroll = function() {myFunction()}; // Get the navbar var navbar = document.getElementById("main-nav-bar"); // Get the offset position of the navbar var sticky = navbar.offsetTop; // Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position function myFunction() { if (window.pageYOffset >= sticky) { navbar.classList.add("sticky") } else { navbar.classList.remove("sticky") } } </script> on my home page i have a hero and the nav is at the bottom of it. It works great, when your scroll to it it sticks. When you scroll back up it attaches back to the content (the bottom of the hero). I have another page that "includes" the nav. It works most of the time but on some page refreshes, the nav loads directly at the top of the page not under the header and when i scroll up and down it stays attached to the top of the screen. The class sticky gets appended and never removed. Any ideas why this would be. There is nothing exciting going on in this project. Currently all static data.
  14. well there ya go....thanks very much!!!!!
  • 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.