-
Posts
597 -
Joined
-
Last visited
Everything posted by Adamhumbug
-
The following allowed me to create an array that is seen by post $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); var taggedPerson = $(this).data('id') $('#peopleLinkedToArticle').val($('#peopleLinkedToArticle').val()+taggedPerson+',') tagButton.appendTo('#taggedInArticleContainer') $('#searchForPeopleBox').val('') $('#searchForPeopleBox').focus(); });
-
I think i am getting pretty close. I have added a text field that i am trying to append the ids to to give me an array of linked people. Issue is, its overwriting not appending. This is jq $('#peopleLinkedToArticle').append().val(taggedPerson+',') this forms part of the selection process shown below. $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); var taggedPerson = $(this).data('id') $('#peopleLinkedToArticle').val(taggedPerson+',') tagButton.appendTo('#taggedInArticleContainer') $('#searchForPeopleBox').val('') });
-
Hi, I have a form for news articles. It has a title and a body which is fine. I also have a search box that allows the user to search for a memeber and click their name when it appears. This moves a div with a data-id into another div. The purpose of this is to tag them in the article. I am able to post all of the simple stuff but how would i post these value. I am assuming that i would need to create an array of said values but i am struggling to get them showing in post at all. Here is the code i have so far <?php function searchForPeople($searchVal, $exclude = '0'){ $sv1 = $searchVal; $sv2 = $searchVal; include 'includes/dbconn.php'; $out =""; $stmt = $conn -> prepare(" SELECT fname, lname, id FROM person WHERE id NOT IN (".implode(',', array_map('intval', $exclude)).") AND (fname LIKE CONCAT('%',?,'%') OR lname LIKE CONCAT('%',?,'%')) "); $stmt -> bind_param('ss', $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle' name='taggedPerson[]' data-id='$pid'>$fn $ln</div>"; } return $out; } ?> ...... <div id="searchResultsHere"> <!-- ajax content here --> </div> <hr> <div id="taggedInArticleContainer"> <!-- ajax content here --> </div> ....... <div class="col-lg-2"> <button type="submit" name="PublishNewNews" class="btn btn-primary w-100 mb-3">Publish</button> <button class="btn btn-primary w-100">Save</button> <hr> <div class="btn btn-warning w-100 mb-3">Private</div> <input type="hidden" name="howVisible" value="Private"> <hr> <p class="text-justify">Private news articles will only be avilable to logged in users</p> </div> ....... <script> $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); tagButton.appendTo('#taggedInArticleContainer') }); $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() var tagged = '0' var tagged = $('#taggedInArticleContainer').find('.tagInArticle').map(function(){ return $(this).data('id'); }).get(); $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal, "exclude" : tagged}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); </script> I hope this is enough to go on. I am sure it is simple but i just cant get it. Thanks all in advance.
-
Javascript moving buttons and adding their ids to a var
Adamhumbug replied to Adamhumbug's topic in Javascript Help
I fixed this by using the following: WHERE id NOT IN (".implode(',', array_map('intval', $exclude)).") -
Javascript moving buttons and adding their ids to a var
Adamhumbug replied to Adamhumbug's topic in Javascript Help
I have made some changes and now have this in there to deal with the Undefined Index. I am now getting array to string conversion errors in the WHERE id != ? -
Javascript moving buttons and adding their ids to a var
Adamhumbug replied to Adamhumbug's topic in Javascript Help
The sent payload of the ajax is ajax=one&val=John+Sm Nothing is mentioned about the exclude data. When i console log tagged after searchval i get a blank array -
Javascript moving buttons and adding their ids to a var
Adamhumbug replied to Adamhumbug's topic in Javascript Help
Sorry its been a while. This nearly works but i get: Which is this line exit(searchForPeople($_POST['val'], $_POST['exclude'])); Here is a code dump <?php if(isset($_POST['ajax'])){ switch($_POST['ajax']) { case 'one': exit(searchForPeople($_POST['val'], $_POST['exclude'])); break; } } function searchForPeople($searchVal, $exclude = 0){ $sv1 = $searchVal; $sv2 = $searchVal; 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', $exclude, $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle$pid' data-id='$pid'>$fn $ln</div>"; } return $out; } ?> <div id="searchResultsHere"> <!-- ajax content here --> </div> <div>Tagged</div> <div id="taggedInArticleContainer"> <!-- ajax content here --> </div> <script> $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); tagButton.appendTo('#taggedInArticleContainer') }); $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() var tagged = $('#taggedInArticleContainer').find('.tagInArticle').map(function(){ console.log(tagged) return $(this).data('id'); }).get(); console.log(searchVal) $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal, "exclude" : tagged}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); </script> -
Javascript moving buttons and adding their ids to a var
Adamhumbug posted a topic in Javascript Help
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; } -
Bingo - thanks very much!!
-
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.
-
Turns out this did it moneyValues.push(parseInt(transIN[i].getAttribute('value')))
-
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
-
Yes that was the answer. Thanks so much
-
It is dynamic - you think onClick() on the where the div is created?
-
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.
-
Upload Photo, Change File Name, Save file name to DB
Adamhumbug replied to Adamhumbug's topic in PHP Coding Help
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"); } -
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."; } }
-
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";
-
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
-
I have uploaded a video of what is happening here https://filebin.net/ur647qv7tqlw62bt
-
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.
-
Subquery, use results from one query in another
Adamhumbug replied to Adamhumbug's topic in MySQL Help
well there ya go....thanks very much!!!!! -
Subquery, use results from one query in another
Adamhumbug replied to Adamhumbug's topic in MySQL Help
When i run the following sql on the following table: SELECT DISTINCT u.user_firstname, u.user_lastname, u.user_id FROM ssm_chat_link cla JOIN ssm_chat_link clb using (chat_id) JOIN ssm_user u on cla.user_id = u.user_id WHERE clb.user_id = 2 +---------+---------+-------------------+ | chat_id | user_id | chat_surrogate_id | +---------+---------+-------------------+ | 1 | 1 | 1 | | 1 | 2 | 2 | | 2 | 1 | 3 | | 2 | 3 | 4 | | 3 | 2 | 5 | | 3 | 4 | 6 | +---------+---------+-------------------+ i would expect to see user id's 2 & 4 But i see 1, 2 & 4 I can see there being many follow up questions to this... sorry in advance -
Subquery, use results from one query in another
Adamhumbug replied to Adamhumbug's topic in MySQL Help
So that does workish...(i was not / am not familiar with self joins) I see what you are doing here - but this is also selecting the person with id 1 and i would like them to be omitted from the results -
Subquery, use results from one query in another
Adamhumbug replied to Adamhumbug's topic in MySQL Help
My thought was i would run one query to find all of the chat_ids that have user_id = 1 and then another query that selects other user_ids that share the chat_id. I cannot work out how to do this simply (in one query). It may be a "cant see the wood for the trees" moment...