Jump to content

Adamhumbug

Members
  • Posts

    316
  • Joined

  • Last visited

Recent Profile Visitors

2,809 profile views

Adamhumbug's Achievements

Advanced Member

Advanced Member (4/5)

1

Reputation

3

Community Answers

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