Jump to content

Adamhumbug

Members
  • Posts

    583
  • Joined

  • Last visited

Posts posted by Adamhumbug

  1. 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.

  2. 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");
    
    
    }

     

  3. 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.";
      }
    }

     

  4. 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";

     

  5. 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

  6. 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.

     

  7. 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

  8. 19 hours ago, Barand said:

    try

    
    SELECT DISTINCT
         u.firstname
      ,  u.lastname
    FROM ssm_chat_link a 
         JOIN
         ssm_chat_link b USING (chat_id)
         JOIN 
         user u  ON a.user_id = u.user_id
    WHERE b.user_id = 1;

     

    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

  9. 15 minutes ago, benanamen said:

    You need to do a JOIN with the table the holds the user info. You only need one query.

    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...

  10. Hi All,

    I have the following table (ssm_chat_link)

    +---------+---------+-------------------+
    | chat_id | user_id | chat_surrogate_id |
    +---------+---------+-------------------+
    |       1 |       1 |                 1 |
    |       1 |       2 |                 2 |
    |       2 |       1 |                 3 |
    |       2 |       3 |                 4 |
    +---------+---------+-------------------+

    I am wanting to select the user_id of every one that shares a chat_id with user_id = 1

    I will then user this info to get the user names of these people and run a foreach in my php to create a button per person.

    I am very stuck with this and although i am sure this is very simple once you know how....i do not.

    Your help is always appreciated.

  11. 32 minutes ago, gw1500se said:

    Yes i had a look at this example.

    Am i correct in thinking that this only loads notifications on page load.  If that is correct, would this mean that i would have to run this code to look for new notifications on every page.  Also would i be correct in thinking that the notifications would not appear unless the users is navigating around pages.  Unless a page can reload, there will be no notifications?

  12. HI all,

    I am building a php application and i am wanting to use notifications.

    At the moment i am just wanting to understand the methodology behind this.

    I dont necessarily have a use case for these notifications yet but i am going to base it off of the following:

    A user submits something to the database, another user gets a notifications that this has happened.  I see the notifications being something appearing in the header bar (saying "you have a notification"...)

    I know that i will need to use ajax for this and JS/JQ but i am not really sure where to start with this.

    I have done some research and have come up a little blank.

    My main question at the moment is how does the submission of data to the database trigger the notification?

    As always and help here is appreciated.

    Kind Regards

    Adam

  13. I have the following script in here if this is going to help

     

    
    	function allowDrop(ev) {
    	  ev.preventDefault();
    	}
    
    	function drag(ev) {
    	  ev
    	  .dataTransfer
    	  .setData("text", ev.target.id);
    	}
    
    	function drop(ev) {
    	  ev.preventDefault();
    	  var data = ev.dataTransfer.getData("text");
    	  ev.target.appendChild(document.getElementById(data)); 
    	  
    	}

     

  14. Hi, not sure if this is more of a JS or PHP question but here goes.

    I have a form that populates people into a box.  There name is on a div that looks like a button.  Also inside the div are 2 hidden inputs. 

    I plan on dragging some people from box 1 into box 2.

    When moving, i would like everyone in box 2 to have their second hidden input to be changed so when i submit it will be clear who was in which box.

    It currently looks like this when populated if that helps anyone.

    <div class="mt-3 col-6">
    	<div class="container border border-dark p-1 h-50" ondrop="drop(event)" ondragover="allowDrop(event)">
    		<div class="alert alert-warning text-center">Making Own Way</div>
    		<div id="2" class="btn btn-primary m-1" data-id="2" data-role="Manager" draggable="true" ondragstart="drag(event)">
    			<input class="staff" name="staff[]" type="hidden" value="2">
    			<input class="transMethod" name="trans[]" type="hidden" value="mow">
    		Chelsea Hockley</div><div id="16" class="btn btn-primary m-1" data-id="16" data-role="Manager" draggable="true" ondragstart="drag(event)">
    		<input class="staff" name="staff[]" type="hidden" value="16">
    		<input class="transMethod" name="trans[]" type="hidden" value="mow">
    	TEST MANAGER</div>							</div>
    </div>
    <div class="mt-3 col-6">
    	<div class="container container border border-dark p-1 h-50" ondrop="drop(event)" ondragover="allowDrop(event)">
    		<div class="alert alert-primary text-center">Need Transport Daily</div>
    	</div>
    </div>

     

  15. When i click my submit button i am posting the following.

    		Array
    (
        [submitStaffOrder] => 
        [staffMember] => Array
            (
                [0] => 2
                [1] => ANYCHEF1
            )
    
        [date] => Array
            (
                [0] => 2020-02-18
                [1] => 2020-02-18
            )
    
        [startTime] => Array
            (
                [0] => 11:01
                [1] => 10:10
            )
    
        [finishTime] => Array
            (
                [0] => 11:01
                [1] => 10:01
            )
    
        [delExisting] => Array
            (
                [0] => 
                [1] => toDel
            )
    
    )

    I would like to update/insert if delExisting is blank and delete if it has toDel in there.

    I have the following but i am pretty sure the if is not working.

    $date = $_POST['date'];
    	$stime = $_POST['startTime'];
    	$ftime = $_POST['finishTime'];
    	$del = $_POST['delExisting'];
    	$staff = $_POST['staffMember'];
    
    $stmt = $conn -> prepare("
    	                         INSERT IGNORE INTO ssm_staff_order (job_id, staff_id, staff_start_time, staff_finish_time, staff_start_date, staff_finish_date) 
    	                         VALUES (?,?,?,?,?,?)
    	                         ON DUPLICATE KEY 
    	                         UPDATE 
    	                         staff_start_time = VALUES(staff_start_time),
    	                         staff_finish_time = VALUES(staff_finish_time);
    	                         ");
    
    	$delstmt = $conn -> prepare("
    		                         DELETE FROM ssm_staff_order
    		                         WHERE staff_id = ?
    		                         AND job_id = ?
    		                         AND staff_start_date = ?
    		                         ");
    
    	foreach ($staff as $key => $staffId) {
    		if ($del == '') {
    			$start = $date[$key].' '.$stime[$key];
    			$finish = $date[$key].' '.$ftime[$key];
    			$stmt -> bind_param('isssss', $jid, $staffId, $start, $finish, $date[$key], $date[$key]);
    			$stmt -> execute();
    		}
    		
    
    		
    		if ($del == 'toDel') {
    			$delstmt -> bind_param('sis', $staffId, $jid, $date[$key]);
    			$delstmt -> execute();
    		}
    	}
    	
    }

    Can i do what i am trying to do or am i way off here?

     

    I struggle with arrays :(

  16. On 2/20/2020 at 4:29 PM, Psycho said:

    You previously stated

    Based on that comment, this might make more sense:

    
    while ($stmt -> fetch())
    {
        $users[$role][$id] =[$fn, $ln];
    }

    You will then have a multidimensional array in a logical format based on the data, like this:

    
    array (
        [Chef] => (
            [8] => ('FName', 'LName')
        ),
    
        [Manager] => (
            [15] => ('jon', 'smith'),
            [2] => ('Chelsea', 'Hockley'),
        )
    )

     

    You could then iterate over the results something like this

    
    foreach($users as $role => $roleUsers)
    {
        //Can add a header for each role here
    
        foreach($roleUsers as $userId => $userData)
        {
            //Within this loop have the following variables:
            // - $role
            // - $userId
            // - $userData['user_firstname']
            // - $userData['user_lastname']
        }
    }

     

    Thanks for that - will be useful.

  17. 15 minutes ago, Barand said:

    PDO statements (and result objects from a query() ) are traversable, so you can just

    
    foreach ($stmt as $row) {
        echo $row ['user_firstname'];
    }

    Unfortunately, mysqli result objects only are traversable, not prepared statements.

    There is a $stmt->get_result() but it is not available in all implementations (native driver only).

    Makes you wonder why people use mysqli.

    You may be stuck with using

    
    while ($stmt->fetch() ) {
       // build array
       $data[] = [ $fn, $ln, $id, $role ];
    }

     

    When i do the following:
     

    while ($stmt -> fetch()) {
            $user =[$role, $fn, $ln, $id];
    
        }

    i only get one result and i know the sql is pulling 3 results.

    I tried using .= but that give me an array to string error.

  18. Hi All,

    I have a select statement

    	$stmt = $conn -> prepare('
    	                         SELECT u.user_firstname, u.user_lastname, so.staff_id, r.role_name
    	                         FROM ssm_staff_order so
    	                         INNER JOIN ssm_user u on so.staff_id = u.user_id
    	                         INNER JOIN ssm_role r on u.user_role_id = r.role_id
    	                         WHERE job_id = ?
    	                         ');
    	$stmt -> bind_param('i', $jid);
    	$stmt -> execute();
    	$stmt -> bind_result($fn, $ln, $id, $role);

    The result looks like this

    +----------------+---------------+----------+-----------+
    | user_firstname | user_lastname | staff_id | role_name |
    +----------------+---------------+----------+-----------+
    | FName          | LName         |        8 | Chef      |
    | jon            | smith         |       15 | Manager   |
    | Chelsea        | Hockley       |        2 | Manager   |
    +----------------+---------------+----------+-----------+

    I am wanting to build an array so that i can foreach the result with the people under the header of their role.

    I know this is not difficult but i am going around and around with it and clearly missing the key part.

    As always your help is appreciated.

  19. I have an array that has comma sep values.

    I am wanting to run a select statement that includes a NOT IN function.

    SELECT user_firstname, user_lastname, user_id
                                FROM ssm_user
                                WHERE user_role_id = ? and where user_id NOT IN(?)

    Is this possible, oir does the ? just represent a literal string.

    If so do i need to convert the array to a string before running the above?

×
×
  • 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.