Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. Yes, this seems to be the issue - i was only using 2 of the values - rookie. I need to look more into the error reporting for sure - thanks all for your input as always. PDO will be something that i will look into but wanted to start with it on a new project - it will come.
  2. I have the following function function getBallInOver($gameId){ include 'includes/dbconn.php'; $sql = "SELECT MAX(id), over_number, ball_in_over from deliveries where game_id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param('i', $gameId); $stmt->execute(); $stmt->bind_result($overno, $ballinover); if($stmt->fetch()){ $out = $overno; } $stmt -> close(); return $out; } which is called from this function function newDelivery($gameId, $runs, $fairDelivery){ include 'includes/dbconn.php'; $batterId = getOnStrikeBatter($gameId); $ballInformation = getBallInOver($gameId); $one = 1; $sql = "INSERT into deliveries (game_id, on_strike_batter_id, runs_scored, fair_delivery, over_number) values (?,?,?,?,?)"; $stmt = $conn->prepare($sql); $stmt -> bind_param('iiiii', $gameId, $batterId, $runs, $fairDelivery, $ballInformation); $stmt -> execute(); if($runs % 2 !== 0){ include 'includes/dbconn.php'; $zero = 0; $one = 1; $sql = "UPDATE batter_in set on_strike=(case when on_strike = ? then ? else ? end)"; $stmt = $conn->prepare($sql); $stmt -> bind_param('iii', $zero, $one, $zero); $stmt -> execute(); } return; } I am getting an error that the over_number cannot be null. I dont understand why the value is null - when i run the sql directly on the server i get the following: MAX(id) = 42, over_number = 1, ball_in_over = 1 Could someone point me in the right direction. For clarity, the function above its call takes the same peramaters and that works fine so i know the function is getting the data it needs.
  3. I found what it was in my code that was outputting the extra div. I had left something in above that wasnt needed. Thanks for your help as always.
  4. I do have one little issue with this. I have the following foreach ($res as $row) { if (!isset($data[$row['house_name']])) { $data[$row['house_name']] = []; } $data[$row['name']][] = [$row['id'], $row['first_name'], $row['last_name']]; } foreach ($data as $team => $players) { $out .= "<div class='col-4'> <h5>$team</h5> "; foreach ($players as $p) { $out.= "<input class='form-control w-100 mb-3' type='text' disabled='disabled' name='' data-value='$p[0]' value='$p[1] $p[2]'>"; } $out .= "</div>"; } return $out; and i am getting a rougue div created before the 2 divs that i am expecting - you can see the 3 col-4s The first one is always blank. I am assuming that this is something simple but i am struggling to see what it is.
  5. Hi All, I have a php function that returns a list of players and which team they play for. I am looking to create an array that at the top level has the teams and then second level will be first and last name of the player. i think i have done this like this $stmt -> bind_result($fn, $ln, $team); $squad = []; while($stmt -> fetch()){ $squad[$team] .= [$fn, $ln]; } Then i am wanting to return the output to my page as a list (for ease of the example) with the team at the top and all of the player underneath: Team 1 Player 1 Player 2 Team 2 Player 3 Player 4 foreach($squad as $team){ $out .= "$team"; foreach($team as $key => $val){ $out.="$key $value"; }; }; I thought that the above could help me but i am getting a bit lost.
  6. Turns out that i have solved this one myself also, the issue was that i was passing a string in the array and not integers. When i changed the data type to 'is' rather than 'ii' the insert worked.
  7. I have created an array that gets passed to php through ajax. case 'createNewGame': exit(createNewGame($_POST['venue'], $_POST['gamedate'], $_POST['home'], $_POST['away'], $_POST['hts'])); break; hts is the array i tried to insert this way function createNewGame($venue, $gamedate, $home, $away, $homeSquad){ $qry = "INSERT INTO game_squad (game_id, player_id) VALUES (?,?)"; $stmt = $conn->prepare($qry); for($i = 0; $i < count($homeSquad); $i++){ $stmt->bind_param('ii', $gameID, $homeSquad[$i]); $stmt -> execute(); } } there is more going on in here with the other variables. When i console log the array before it is passed into php i can confirm i am getting an array: Array [ "20", "21" ] A point in the right direction here would be appreciated.
  8. Turned out to be a miss-capitalised bit of data createNewgame should have been createNewGame Sorry all. Thanks for looking anyway.
  9. Hi All, I have an ajax call: $('#createNewgame').click(function(){ var errors = []; var gv = $('#gameVenue').val(); var ht = $('#homeTeam').find(":selected").val(); var at = $('#awayTeam').find(":selected").val(); if(gv == '') { $out = "Game Venue"; errors.push($out); } if(ht == 0) { $out = "Home Team"; errors.push($out); } if(at == 0) { $out = "Away Team"; errors.push($out); } if(errors.length != 0){ var finalArray = arrayToStringWithComma(errors) $('.newGameAlertContainer').html("<div class='alert alert-warning newGameAlert hiddenForFade'>"+finalArray+" must be completed!</div>") $('.newGameAlert').fadeIn().delay(3000).fadeOut(1000); return; } if (errors.length == 0){ $.ajax({ type: 'post', data: {'ajax': 'createNewgame', 'venue' : gv, 'home': ht,'away': at }, success: function(resp){ console.log(resp) }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("Status: " + textStatus); alert("Error: " + errorThrown); } }) } }) then i have if(isset($_POST['ajax'])){ switch($_POST['ajax']){ case 'createNewGame': exit(createNewGame($_POST['gv'], $_POST['ht'], $_POST['at'])); break; } } function createNewGame($venue, $home, $away){ include 'includes/dbconn.php'; $qry = "INSERT INTO game (venue, home_team, away_team) VALUES (?,?,?)"; $stmt = $conn -> prepare($qry); $stmt -> bind_param('sii', $venue, $home, $away); $stmt -> execute(); $gameID = mysqli_insert_id(); $_SESSION['activeGame'] = $gameID; return "i ran"; } the success response that i am console logging is the entire html of the whole page. All of this code appears in the same file. Any ideas or pointers? All help appreciated, and have a great new year!
  10. Hi All, I have been messing around with some of my projects and have discovered what i assume is quite a regular "issue" in projects. When i have a file in a folder, not in the same folder as most of webpage files, including the header is leading to some issues. For example, if the layout is as follows My Project - home.php - index.php - includes - header.php - testing - test.php - style - custom.css if i include the header on every page with include 'includes/header.php'; and the header includes the style with include './style/custom.css'; on every page that i create in this new testing folder, which is a copy of a page that might exist elsewhere, i am having to change the path of the includes. I have started to look at using the below (which doesnt follow my file strucure) // Predefined path. define('PATH', '/home/ftpuser/public_html/includes/'); include(PATH . 'myscript.php'); i understand what is going on here. Long winded, but my question is. Is the a standard to where these paths should be stored. I dont want to put them in every file, the header file doesnt seem right. Should i create a new file for things like this "paths.php"? Secondly, would people recommend the above or superglobal paths with: // Superglobal path. include(dirname(__FILE__) . '/myscript.php'); I know that the answer to this is likely going to be put them whereever you want, personal preference etc but i am looking for a bit of advice coming from experience about where these would be put in your projects. Thirdly, how would i go about linking css and js files in plain html using these paths, is this possible without opening php inside the link? Thanks as always in advance and have a great new year!
  11. HI all, I am looking for some best practice help here. I have a php function called with AJAX and on failure, i would like it to create an alert bar on the page that fades out. I have the know how to show the message on the page but i am doing this using a prepend. I know that this should be handled with JS but i am not sure of the best practice to achive what i am after. Any pointers here appreciated. I have attached the function incase that is useful. function showNewItemAfterBCScan($serial_number, $personId){ include 'includes/dbconn.php'; $out="<div id='assigningKitAlert' class='alert alert-warning'>Bar Code Incorrect</div>"; $stmt = $conn -> prepare(" SELECT ks.id, ks.serial, km.model_name, kf.kit_family from kit_serial ks inner join kit_model km on ks.kit_model = km.id inner join kit_family kf on ks.kit_family = kf.id where ks.serial = ? "); $stmt -> bind_param('i', $serial_number); $stmt -> execute(); $stmt -> bind_result($id, $serial, $mname, $kfamily); if($stmt -> fetch()){ $out = <<<OUTPUT <div class='row bg-secondary m-1 center-all'> <div class='col-2 text-center'> <img class='device-thumb py-3' src='img/DP4800e-Front.png' alt=''> </div> <div class='col-10'> <div class='row'> <div class='col-4'> <h4>$mname</h4> </div> <div class='col-4'> <h4>$kfamily</h4> </div> <div class='col-2'> </div> <div class='col-2'> <h1>x 1</h1> </div> </div> <div class='row'> <div class='col-12'> $serial </div> </div> </div> </div> </div> OUTPUT; assignKit($serial_number, $personId); } $stmt -> close(); return $out; }
  12. Final solution if it is useful for anyone. function barCodeVal(event){ var e = event.keyCode; var et = event.target if(e === 13){ barCode = et.value console.log(barCode); $.ajax({ type: 'post', data: {'ajax' : 'one', 'barCode': barCode }, success: function(resp){ $('#barCodeOutput').prepend(resp); } }) } } Thanks @Barand
  13. I thought i would be back. I now have the following: function barCodeVal(event){ var e = event.keyCode; console.log(e) if(e.keyCode === 13){ barCode = e.val() console.log(barCode); $.ajax({ type: 'post', data: {'ajax' : 'one', 'barCode': barCode }, success: function(resp){ $('#barCodeOutput').prepend(resp); } }) } } The first console log works and shows 13 as the output. The second console log does not fire suggesting that the if statement is not picking this up. Any helpers appreciated.
  14. I am sorry all, as is always the case i have answered by own question shortly after posting. function barCodeVal(e){ var code = e.keyCode; console.log(e.keyCode); } thanks anyway, i am sure i will be back.
  15. Hi all, I have an input box that is created dynamically. Before it was created dynamically, it was always in the dom and the following code did what i wanted. $('#serialNumber').keyup(function(e){ if(e.keyCode === 13){ barCode = $(this).val() console.log(barCode); $.ajax({ type: 'post', data: {'ajax' : 'one', 'barCode': barCode }, success: function(resp){ $('#barCodeOutput').prepend(resp); } }) } }) now that it is not part of the dom when the page loads, i am calling it with a key up on the html element. I dont know why i am struggling with this so much but i am really struggling to call the function and pass the keycode into it. I have the following which does give me the keycode but having the second function in the first as it is obviously doesnt do what i want. function barCodeVal(){ $(document).keyup(function(e){ console.log(e.keyCode); }) } I would really appreciate a helping hand on this one - google just shows me react explanations.
  16. Thank you for this. Using this method, is there anyway for me to reference the keys rather than the position. So for example when echoing out i could use $id, $ay, $aw?
  17. Perfect answer as always. That did of course work, as for getting the data out of the other end, could you lend a hand with that also please?
  18. Hi All, I have been scouring the internet for a good source that shows how to create an array and loop through it to output it to the page. I have done this several times but everytime it comes to doing it i have to scratch my head and google to get anywhere near the answer. I have created a 2 dimentional array of data using the following: function getExistingAwards(){ include 'includes/dbconn.php'; $stmt = $conn -> prepare("SELECT id, award_name, award_year, award_winner from award"); $stmt -> execute(); $stmt -> bind_result($id, $an, $ay, $aw); $awards = array(); $out = ''; while($stmt -> fetch()){ $awards[$ay] = [$id, $an, $aw]; } } This gives me a data structure that looks like this. Array ( [2021] => Array ( [0] => 1 [1] => Avenue Park Award [2] => 1 ) [2019] => Array ( [0] => 2 [1] => Avenue Park Award [2] => 1 ) ) Issue 1 - This looks correct but if there are more than one entries that has the year 2021 for example, only the last one will be added to the array. Issue 2 - After i have the correct data in the array how do i go about looping through each level of the array. I really struggle with for each loops. As always, your help is appreciated.
  19. Thanks so much and i appreciate you dealing with my rubbish post.
  20. prs_ptd_id is a typo - it should be pr_ptd_id pr_op_id is the id of the person that made the order stored on the order table (prs_pr) and links to op_id in the person table (prs_op) prs_ptd_id (is the order definition) pr_o_id is the organisation the order is stored against in the order table (prs_pr) this links to o_id stored in the organiastion table (prs_o) orders belong to a person and the person belongs to an organsation
  21. prs_o table: o_id, o_name prs_op table: op_id, op_o_id - op_o_id joins to o_id from above prs_pr table: pr_Id, pr_op_id, prs_ptd_id, pr_ip2ptd_id - pr_op_id joins to op_id from 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.