Jump to content

Adamhumbug

Members
  • Posts

    349
  • Joined

  • Last visited

Everything posted by Adamhumbug

  1. So if the user selects a client from a dropdown (named clientName) then there will be an id available, if the user selects add new client, the dropdown is replaced with an input named clientNameNew. So one of the two will be posted but there is no way of knowing which it will be. But ultimately, as set up, i dont know if there will be a post value of clientNewName and need to do something different if it is posted from if an existing client is selected from the list. The reading that i have done suggests that isset is the way to go and shouldnt produce a warning, but i am still getting one:
  2. ok this is interesting. On first try i am getting "Unknown column 'job_id' in 'from clause'" but there isnt a job_id in the from clause?
  3. I have a from that posts when i click submit, one of the inputs is created if you create a new client rather than picking one from a select. If creating a new client, an id will not be passed in and therefore will be undefined. I thought i had handled it with the following but i am getting a notice of undefined index on "clientNameNew" //if createing a new client name if ($_POST['clientNameNew']) { $clientName = $_POST['clientNameNew']; $clientId = createNewClient($pdo, $clientName); } else { $clientId = $_POST['clientName']; } Is there a better way of handling this than the way i have above?
  4. Thanks both for the explanations. **removing endless includes for db from code now**
  5. I have a php function that is called via ajax: function getItemAttributesById($itemId){ require 'includes/dbconn.php'; $sql = "SELECT id, name, type, price_uk, price_us, price_ca, price_au, price_eu, billing_freq from item where id = :itemId"; $stmt = $pdo->prepare($sql); $bindData = [ 'itemId' => $itemId ]; $stmt->execute($bindData); $item = $stmt->fetch(PDO::FETCH_ASSOC); echo json_encode($item); } when i echo the $item at the end of the function and console.log the response in ajax, i can see the array. When i use the return keyword instead of echo i just see the word "Array". From my understanding of what they do, i wouldnt have thought there would have been a difference in what got back to the ajax function. Am i using it wrong?
  6. for this do you mean that function getItemsForQuote($itemType, $currency, $qty = null, $itemId = null, $startDate = null, $endDate = null,$priceQuoted = null, $notes = null) should be replaced with one array containing all of this data rather than lots of individual elements?
  7. All good points here - you are correct and i have ammended my code.
  8. I think i need to read this a few more times and see if i can make that work. I may be back for this comment. Thanks for taking the time, it is appreciated.
  9. If more information is needed for this i will be happy to supply it, i didnt want to overload with too much info in one place.
  10. Hi All, I think this may be a bit of a slog to get to the answer here as there are a fair few function calls and quite long functions. I have a function that is called by ajax to create some form items. This works fine. The form can be filled out and all of the data goes to the DB. Now, when wanting to recreate the form, filled with the data, so that users can edit i have part of the function that should be setting the selected item in an option list that is outputting the value where no match has been found rather than the value when a match has been found. here is the big function function getItemsForQuote($itemType, $currency, $qty = null, $startDate = null, $endDate = null, $itemId = null, $notes = null) { require 'includes/dbconn.php'; $sql = "SELECT id, name, price_uk, price_us, price_ca, price_au, price_eu, billing_freq from item where type = :item_type"; $stmt = $pdo->prepare($sql); $stmt->bindParam(':item_type', $itemType); $stmt->execute(); $items = $stmt->fetchAll(PDO::FETCH_ASSOC); if ($items) { $qtyArray = array( 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => '10', 11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15', 16 => '16', 17 => '17', 18 => '18', 19 => '19', 20 => '20' ); $out = "<div class='row mb-3 completeLine'><div class='col-1'> <select name='itemQty[]' class='itemQty form-select'>"; foreach ($qtyArray as $key => $value) { if ($qty == $key) { $selected = 'selected'; $out .= "<option selected='{$selected}' value='{$key}'>{$value}</option>"; } $out .= "<option value='{$key}'>{$value}</option>"; } $out .= "</select> </div> <div class='col-4'> <select name='itemSelected[]' class='itemSelected form-select'><option selected disabled>Please Select</option>"; foreach ($items as $item) { if ($itemId == $item['id']) { $selected = 'selected'; $out .= "<option selected='{$selected}' value='{$item['id']}'>{$item['name']}</option>"; } $out .= "<option data-billingfreq='{$item['billing_freq']}' data-priceuk='{$item['price_uk']}' data-priceus='{$item['price_us']}' data-priceca='{$item['price_ca']}' data-priceau='{$item['price_au']}' data-priceeu='{$item['price_eu']}' value='{$item['id']}'>{$item['name']}</option>"; } $out .= "</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-7 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 class='col-3 mt-3'> <div class='input-group mb-3'> <span class='input-group-text pricePerWeek'>PPW</span> <input type='text' class='pricePerWeek form-control' placeholder='PPW'> </div> </div> <div class='col-2 mt-3'> <div class='input-group mb-3'> <span class='input-group-text noOfWeeks'>Weeks</span> <input type='text' class='noOfWeeks form-control' placeholder='Weeks'> </div> </div> </div> </div> "; } return $out; } The section that is not working correctly is foreach ($items as $item) { if ($itemId == $item['id']) { $selected = 'selected'; $out .= "<option selected='{$selected}' value='{$item['id']}'>{$item['name']}</option>"; } $out .= "<option data-billingfreq='{$item['billing_freq']}' data-priceuk='{$item['price_uk']}' data-priceus='{$item['price_us']}' data-priceca='{$item['price_ca']}' data-priceau='{$item['price_au']}' data-priceeu='{$item['price_eu']}' value='{$item['id']}'>{$item['name']}</option>"; } itemId is being passed into this function correctly i believe which has been checked with the function that calls this one below. The $itemId which is passed in = 2 and the $item['id'] that is being pulled in from the database in this query should match. The above function is called from the following function function rebuildQuote($quoteId, $version) { include 'includes/dbconn.php'; $sql = "SELECT item_id as itemId,quote.currency as quoteCurrency, item.type as itemType, quantity, from_date, to_date, price_quoted from quote_items inner join item on item.id = quote_items.item_id inner join quote on quote.id = quote_items.quote_id where quote_id = :quoteId and quote_items.version = :version"; $stmt = $pdo->prepare($sql); $bindData = [ 'quoteId' => $quoteId, 'version' => $version ]; $stmt->execute($bindData); $items = $stmt->fetchAll(PDO::FETCH_ASSOC); $out = ""; if ($items) { foreach ($items as $item) { $out .= getItemsForQuote($item['itemType'], $item['quoteCurrency'], $item['quantity'], $item['itemId']); // $out .= $item['itemId']."and"; } } else { $out .= "no items"; } return $out; } You will see that i have been changing the $out at the end to check what variables are being sent into the function call. I have been going around the houses on this but any pointers in the right direction would be appreicted. I am hoping that it is a "cant see the woods for the trees" issue.
  11. This was a mistake that was corrected on my last posting. I origionally did it to check that the issue was not with the params that were passed into the function.
  12. Actually, that did seem to do the trick - i had been playing with the version definition in the $bindData - when i set that back to $version it worked. Thanks for that, i had a feeling it would be something small. Do you know why that has been causing the issue, i have tons of other queries with quotes around them that seem to work ok?
  13. i updated to this with no change 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.$version; }
  14. 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.
  15. 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?
  16. 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?
  17. 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.
  18. 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.
  19. 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...
  20. 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); }) }
  21. 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) }) }) }
  22. 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.
×
×
  • 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.