Jump to content

Adamhumbug

Members
  • Posts

    349
  • Joined

  • Last visited

Recent Profile Visitors

3,180 profile views

Adamhumbug's Achievements

Advanced Member

Advanced Member (4/5)

1

Reputation

6

Community Answers

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