Jump to content

Adamhumbug

Members
  • Posts

    585
  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. i have the following function function rebuildQuote($quoteId, $version){ include 'includes/dbconn.php'; $sql = "SELECT item_id as itemid, quantity, from_date, to_date, price_quoted from quote_items where quote_id = ':quoteId' and version = ':version'"; $stmt = $pdo->prepare($sql); $bindData = [ 'quoteId' => $quoteId, 'version' => 1 ]; $stmt->execute($bindData); $items = $stmt->fetchAll(PDO::FETCH_ASSOC); $out = ""; if($items){ foreach($items as $item){ $out .= "this"; } }else{ $out .= "no items"; } return $out; } when i return $quoteId and $version i can see 19,4 so i know that vars are coming into this function. When i run the SQL manually in the db i get 2 rows of data. When i run the function as is i get "no items" I cant see what i am doing wrong here.
  2. I have the below query: SELECT max(quote.id) as quoteId, job_id as jobId, job.name as jobName, job.client_id as clientId, client.name as clientName, currency, version from quote inner join job on job.id = quote.job_id inner join client on client.id = job.client_id where quote.closed != '1' group by job_id i have attached an image of the data structure when i run the qry i am getting quoteId jobId jobName clientId clientName currency version 13 21 Test Job 12 Test Client GBP 1 14 22 JOB JOB 3 Testing LTD USD 1 19 24 Adams Job 13 Adams Co GBP 1 but i would be expecting the version numbers of the quote ids selected to be 8, 1 and 4. Could anyone point me at what i am doing wrong with my sql?
  3. Hi all, I have a function that is returning data from a select statement. I am wanting to change the fields that are returned dynamically based on a variable that is passed into the function. I thought i would be able to do this with a switch and a variable name in the select statement. I have done some reading and it seems that this is not a thing that can be done. Would the best option be to get all fields that i might want to decide which to use after the data has been returned?
  4. I have numbers stored in a database in pence (or cents). For example i have an item that costs 100 pounds stored as 10000 as this is the number of pence in 100 pounds. When i am working with Jquery, how would i show the value as 100 pounds. I have chosen this route based on some research with maths issues of storing it in pounds should their be decimals to calculate. I was concidering a division by 100 but i am not sure what the recommended method for working with currency like this is for display only purposes.
  5. Thanks all for your feedback. @mac_gyver and @Barand - both of your solutions worked perfectly out of the box so that is very much appreciated.
  6. I am actually getting undefined variable on both qty and item. The console logs indicate that they are set and they are all set in the same function so i am a bit lost. I am not sure that what i am doing is the best way of going about this...
  7. I have got to this stage but i am getting qty is not defined when i try and set the linetotal box function calcLineTotal(){ $('.completeLine').each(function(){ $(this).find($('.itemQty')).each(function(){ var qty = $(this).val(); console.log(qty) }) $(this).find($('.itemSelected option:selected')).each(function(){ var item = $(this).data('priceuk') console.log(item) }) var linetotal = qty * item; $(this).find($('.lineTotal')).val(linetotal); }) }
  8. I think i have made a pretty solid start function calcLineTotal(){ $('.completeLine').each(function(){ $(this).find($('.itemQty')).each(function(){ var qty = $(this).val(); console.log(qty) }) }) }
  9. I have a form that creates new rows on a button click - i am wanting to do maths on these rows. The form when created has the following html and new rows create mostly the same thing (just the data in the drop down differs). <div class="row mb-3 completeLine"> <div class="col-1"> <select name="itemQty[]" class="itemQty form-select"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </div> <div class="col-4"> <select name="itemSelected[]" class="itemSelected form-select"> <option data-priceuk="1000000" value="1">Annual AllowMe Licence</option> <option data-priceuk="300000" value="2">Single Event Licence</option></select> </div> <div class="col-2"> <input name="fromDate" type="date" class="form-control from-date"> </div> <div class="col-2"> <input name="toDate" type="date" class="form-control to-date"> </div> <div class="col-2"> <input name="lineTotal" type="text" disbaled="" placeholder="Total" class="line-total form-control"> </div> <div class="col-1"> <div class="btn btn-primary w-100">Opt</div> </div> <div class="col-12 mt-3"> <div class="input-group mb-3"> <span class="input-group-text">Notes</span> <input name="lineNotes" type="text" class="line-notes form-control" placeholder="Add notes for line item"> </div> </div> </div> I am wanting to multiply the quanity on each line by the value of the item. The bit i am struggling to remember is how to write the JQ to select the items from each line to multiply, i will be wanting to add on change events to these also. Each line gets a completeLine class I am thinking it will be a for each with a find but i cant string it together.
  10. Thanks again - all up and running. I am sure i will be back.
  11. I think that was the issue here, i removed the bit you suggested and all seems to be working - looks like i was breaking the variable there. Thanks very much!
  12. So i am calling the function like this: <?=getClientName($pdo, 'select');?> and needed to ammend the function name like this:? function getClientName($pdo, $display) That gives me: Fatal error: Uncaught Error: Call to a member function query() on int in /homepages/20/d832698785/htdocs/platforms/quote-master/includes/functions.php:9 Stack trace: #0 /homepages/20/d832698785/htdocs/platforms/quote-master/new-quote.php(12): getClientName(1, 'select') #1 {main} thrown in /homepages/20/d832698785/htdocs/platforms/quote-master/includes/functions.php on line 9
  13. I am brand new to PDO and i am very sure this is a simple issue but i am struggling to work it out. My connection file: <?php $host_name = '*******.hosting-data.io'; $database = '******'; $user_name = '******'; $password = '******!'; try { $pdo = new PDO("mysql:host={$host_name}; dbname={$database}", $user_name, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?> and the function that i am trying to run: function getClientName($display) { $pdo = require 'includes/dbconn.php'; $sql = "SELECT id, name from clients"; $stmt = $pdo->query($sql); $clients = $stmt->fetchAll(PDO::FETCH_ASSOC); if ($display == 'select') { if ($clients) { $out = "<div class='input-group mb-3'> <label class='input-group-text' for='inputGroupSelect01'>Client Name</label> <select class='form-select' id='inputGroupSelect01'> <option selected disabled>Please Select</option> <option value='0'>-- New Client --</option>"; foreach ($clients as $client) { $out .= "<option value='{$client['id']}'>{$client['name']}</option>"; } $out .= "</select> </div>"; } } return $out; } I am getting an error on line 9 of the function which is: $stmt = $pdo->query($sql); I am trying to figure out what is causing this error and if my PDO is not correct. I am getting the connection successful message.
  14. very useful info - thanks for that - i could well be back here for help but ill have a stab.
  15. I am wanting to create a pdf document. Basically a branded document that pulls data from the database and builds a quote that would be sent to a client.
  16. Hi all, I wasnt sure of the best place to put this thread so would appreciate the admins advice on that. I have a web app and i am wanting it to be able to create a downloadable pdf. I am early in the process but i am assuming that i create the view that i want to pdf in html/css. Can anyone suggest the best way for me to go about creating this PDF or any third party add ons that i could be using. @Barand will be happy to know this will be a PDO project, although a simple one to start.
  17. 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.
  18. 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.
  19. 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.
  20. 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.
  21. 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.
  22. 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.
  23. 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.
×
×
  • 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.