Jump to content

new2you

Members
  • Posts

    11
  • Joined

  • Last visited

new2you's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello again folks, Thanks for "opening my eyes" to the fact that I should have first thought (and used) "Database Normalization", as opposed to "Storing concatenated/delimited values in a text field". It now makes sense to me, and I now have some more questions and a further plea for coding help. So, based on your suggestions, what I've now done is that I've created two new tables as follows: 1) A master file (named weekdays_master), which has 7 rows, one for each day of the week (structure displayed in first attached image) 2) A transaction file (named selected_weekdays), which may contain upto 7 rows per transactionID (depending on how many days are selected/checked in the data-entry form) - structure displayed in the second attached image First question: does the structures for the two new tables look good, or have I got it all wrong? Second question: Can/should I use the weekdays_master table (in some way or the other) to display and/or accept the checkbox values on the form...or should I just hard-code values as part of the form HTML? If the former is suggested, how would I go about doing it? Appreciate if I could receive some code help. The HTML code for the checkboxes is shown below: <div class="control-group"> <label class="control-label">Limited Time Sale Days:</label> <div class="lts-checkboxes-container"> <label class="indent-to-the-left"> <input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='F' <?php echo $lts1; ?>><span class='no-highlight'>Fri</span> </label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Sa' <?php echo $lts2; ?>><span class='no-highlight'>Sat</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Su' <?php echo $lts3; ?>><span class='no-highlight'>Sun</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='M' <?php echo $lts4; ?>><span class='no-highlight'>Mon</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Tu' <?php echo $lts5; ?>><span class='no-highlight'>Tue</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='W' <?php echo $lts6; ?>><span class='no-highlight'>Wed</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Th' <?php echo $lts7; ?>><span class='no-highlight'>Thu</span></label> </div> </div> Now, upon clicking the "Submit/Update" button, I would obviously also have to create (or delete) a transaction each (in the selected_weekdays table) for each weekday that was checked/selected (or unchecked/unselected) on the form, with the main transaction_ID as the foreign key. And that of course is in addition to the main transaction record itself being updated (with any changes made by the user). So, how would I go about doing that i.e. writing (or deleting) many (up to 7) records in the selected_weekdays table, for the one transaction_id? Again, providing the necessary code will be most helpful, since I'm still very new to this, and this is certainly way beyond my current skills. Much thanks again for all the help and advice you wonderful people are giving me. Appreciate it!
  2. @Barand and @Jacques1, Perhaps I should have mentioned, and I'm sorry that I didn't but I've setup most of those fields as VARCHAR, including the field titled LT.S....and therfore, during the testing stage, I've only been typing-in numbers, to make date-input quick and easy. I know it's not the right thing to do. but I must admit my fault. @Jacques1, I will certainly look into what you've suggested, and I'll even need to digest the little bit of coding help you've provided, before I come back with more questions. Thanks
  3. @Barand, I do know a bit about data normalization...and I've tried my to normalize my tables as best as possible....but I certainly wasn't aware that I could/should normalize them to achieve what I'm asking for. Let me rephrase that: since I don't know what I don't know, I have no idea how I can use normalization to get the answer that I'm seeking. I just have no idea what (more) I should be doing to normalize my tables in order to store the selected values differently. Let me also ask you 2 questions: 1) Why is it a no-no to store a delimited list in a field? 2) When you say I'm storing numeric values in the same column, are you refering to the hyphen/minus sign? If yes, I'm curious again to know why that's an issue. Thanks for your reply, and for trying to help.
  4. Hello All, Being a newbie at PHP coding I'm at my wits end trying to figure out: a) how to pull-in values from a delimeted text field (in a MySQL table) and check/select the appropriate checkboxes, based on the values that were stored in the text field, b) how to write any changes (made by the user) back to the tables' text field. Note that this is for an "update.php" file/process. My "create.php" file/process uses the following HTML to display and accept the checkbox values: <div class="control-group"> <label class="control-label">Limited Time Sale Days:</label> <div class="lts-checkboxes-container"> <label class="indent-to-the-left"> <input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='F'><span class='no-highlight'>Fri</span> </label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Sa'><span class='no-highlight'>Sat</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Su'><span class='no-highlight'>Sun</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='M'><span class='no-highlight'>Mon</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Tu'><span class='no-highlight'>Tue</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='W'><span class='no-highlight'>Wed</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Th'><span class='no-highlight'>Thu</span></label> </div> </div> And the code (certainly not the best code in the world, but it works) to collect, delemit/concatenate, and save to DB is as follows: if(empty($_POST['limited_time_sale'])) { // echo("You didn't select any weekday."); $selected_lts = ''; $limited_time_sale = ''; } else { $limited_time_sale = $_POST['limited_time_sale']; $N = count($limited_time_sale); $selected_lts = ''; // echo("You selected $N DoW(s): "); for($i=0; $i < $N; $i++) { // echo($limited_time_sale[$i] . " "); if ($i < ($N - 1)) { $selected_lts .= $limited_time_sale[$i] . "-"; } else { $selected_lts .= $limited_time_sale[$i]; } } } if(!empty($selected_lts)) { $limited_time_sale = $selected_lts; } Now, I've figured out how to bring-in, and separate the stored values using the following code, however I have no idea what to do next...in order to have only the approprite boxes checked/selected (in the event that all boxes were not selected during the create stage). $limited_time_sale = isset($values['limited_time_sale']) ? $values['limited_time_sale'] : ''; $checked_lts = explode("-", $limited_time_sale); In my "update.php" file, the HTML for the forms' checkboxes is as follows: <div class="control-group"> <label class="control-label">Limited Time Sale Days:</label> <div class="lts-checkboxes-container"> <label class="indent-to-the-left"> <input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='F' <?php echo $lts1; ?>><span class='no-highlight'>Fri</span> </label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Sa' <?php echo $lts2; ?>><span class='no-highlight'>Sat</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Su' <?php echo $lts3; ?>><span class='no-highlight'>Sun</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='M' <?php echo $lts4; ?>><span class='no-highlight'>Mon</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Tu' <?php echo $lts5; ?>><span class='no-highlight'>Tue</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='W' <?php echo $lts6; ?>><span class='no-highlight'>Wed</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Th' <?php echo $lts7; ?>><span class='no-highlight'>Thu</span></label> </div> </div> Attached picture shows that selected checkboxes are saved to the text field as/in the format of "F-Sa-Su-M-Tu-W-Th" - if all checkboxes/weekdays were selected....or as "Sa-M-W-Th" - if only Sat, Mon, Wed, and Thu checkboxes were selected Thanks.
  5. @Psycho, much thanks for re-writing and simplyfying that function of mine. It looks waaaay simpler now - very easy to understand and debug. So, here's another thing I found out (last night), when I decided to temporarily stop using the function and instead duplicated the HTML for all fields. When I have all the input fields (6 of them) being processed (i.e. uncommented), the wierd behaviour rears its ugly head i.e. I don't see the echo statement that says that reads ""Starting the code block for the TRUE condition", but yet a record gets created. @kicken: as you suggested, I did change my "INSERT INTO..." statement to hard-code a value for one of the fields, and yes, the hard-coded value is being inserted into the table...which means that the contol is somehow getting into the TRUE portion, but without displaying a number of echo statements that I've put in place. Spooky 'eh? Perhaps I should wait until after Halloween, and see if the ghosts have left my code :-) Just kidding! Anyways, the other thing is that if/when I remark out any one of those fields (and I mean, any one), the code seems to work the way I expect it to work. So, why is it that when input for 5 fields are being requested it works fine, but yet, when a 6th field is being added it goes crazy? Any further ideas/suggestions for me to try? This one is really driving me insane! The changed code is below: <!-- Commenting out this block of code, and replacing it with the block of code just below this one <?php echo standardInputField('Qty/Pkg', 'qty_pkg', $qty_pkg, $errors); ?> <?php echo standardInputField('Pkg. Of', 'pkg_of', $pkg_of, $errors); ?> <?php echo standardInputField('Price', 'price', $price, $errors); ?> <?php echo standardInputField('Flyer Page #', 'flyer_page', $flyer_page, $errors); ?> <?php echo standardInputField('Limited Time Sale', 'limited_time_sale', $limited_time_sale, $errors); ?> <?php echo standardInputField('No(s) to Purchase', 'nos_to_purchase', $nos_to_purchase, $errors); ?> --> <!-- The code below is now being used instead of the block above --> <div class="control-group"> <label class='control-label'>Qty/Pkg:</label> <div class='controls'> <input type="text" name="qty_pkg" id="qty_pkg"> </div> </div> <div class="control-group"> <label class='control-label'>Pkg. Of:</label> <div class='controls'> <input type="text" name="pkg_of" id="pkg_of"> </div> </div> <div class="control-group"> <label class='control-label'>Price:</label> <div class='controls'> <input type="text" name="price" id="price"> </div> </div> <div class="control-group"> <label class='control-label'>Flyer Page #:</label> <div class='controls'> <input type="text" name="flyer_page" id="flyer_page"> </div> </div> <div class="control-group"> <label class='control-label'>Limited Time Sale:</label> <div class='controls'> <input type="text" name="limited_time_sale" id="limited_time_sale"> </div> </div> <div class="control-group"> <label class='control-label'>Nos to Purchase:</label> <div class='controls'> <input type="text" name="nos_to_purchase" id="nos_to_purchase"> </div> </div>
  6. I've gone so blind to this code that I now cannot even see the "label within label" that you're refering to. Where do you see it? Essentially this function is being used in order to avoid having to hard-code the same HTML for multiple fields (which were of the same input type). While it did serve to shorten the code (albeit slightly), it sure did add a fair amount of complexity to the code, I'm sure. But now that I think of it, perhaps I should actually hard-code separately for each field, especially now that I'm changing some textboxes to radiobutton and/or checkboxes.
  7. I'm now wondering/hoping someone can check the following function to see if there might be something wrong in there. I ask this because I've now found out that it's not specifically the statement in the post above that is causing the problem, but any similar statement (for a different field/value) is also causing similar behaviour...so perhaps it might be something to do with the function. //Since you want the format for the input fields to be the same, //You can create a function to create them function standardInputField($fieldLabel, $fieldName, $fieldValue, $errorsAry) { $fieldHTML = "<div class='control-group'>\n"; $fieldName == "new_store_name" || $fieldName == "new_item_name" ? $fieldHTML .= " <label id='label-new-store-or-item' class='control-label'>{$fieldLabel}</label>\n" : $fieldHTML .= " <label class='control-label'>{$fieldLabel}</label>\n"; $fieldHTML .= " <div class='controls'>\n"; $fieldName == "new_store_name" || $fieldName == "new_item_name" ? $fieldName == "new_store_name" ? $fieldHTML .= " <input class='other-store-or-item' id='new_store_name' type='text' name='{$fieldName}' value='{$fieldValue}' />\n" : $fieldHTML .= " <input class='other-store-or-item' id='new_item_name' type='text' name='{$fieldName}' value='{$fieldValue}' />\n" : $fieldHTML .= " <input type='text' name='{$fieldName}' value='{$fieldValue}' />\n"; //If the field has an error, display it. if(isset($errorsAry) && in_array($fieldName, $errorsAry)) { $fields = fieldsArrayForCreateUpdate(); $fieldHTML .= " <span class='error-message'>" . $fields[$fieldName]['error'] . "</span>\n"; } $fieldHTML .= " </div>\n"; $fieldHTML .= "</div>\n"; return $fieldHTML; } Thanks.
  8. Guys, thanks a lot for taking the time to read, understand, and reply to my plea for help (especially you @Psycho, since you understood my very first post perfectly)...much appreciated! Okay, so here's what I did (after trying almost all of the suggestions provided by you wonderful folks), and what I found out: I reverted to an older copy of my create.php file (wherein I was accepting all input in the form of textboxes only...and not as radiobuttons, checkboxes etc.) and found that the problem existed (all along) and in that code as well, and that the problem seems to be related to the following line, which if/when I comment out will allow control to go into the TRUE portion. But, as long as the following line is not commented out, control does not go into the TRUE condition, but yet, the record does get created - for some strange reason. <?php echo standardInputField('Qty/Pkg', 'qty_pkg', $qty_pkg, $errors); ?> Other than saying that I'm stumped, I have no idea what else I can do, or even say...because this just does not make sense to me. I certainly don't wish to give up, but at the same time I don't know how to move on, and get this resolved....catch 22!
  9. @NotionCommotion, I tried validating my code but wasn't successful since I'm currently developing this on a non-public IP address..and the validator no longer works for non-public IP addresses. @ginerjm, My apologies for making it look so confusing...hope it's easier to understand now :-) In the code below, I used to have just the first statement...which essentially accepted input as a textbox for a text field named qty_pkg (in the underlying MySQL table)...and that used to work just fine. <!-- <?php echo standardInputField('Qty / Pkg', 'qty_pkg', $qty_pkg, $errors); ?> --> <div class="control-group"> <label class="control-label">Priced by:</label> <div class="priced-by-radio-container"> <div class="pb-radiobuttons-container"> <label class="indent-to-the-left"> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='UoM' $pb1> <span class='no-highlight'>Unit of Measure</span> </label> <label> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='Qty' $pb2> <span class='no-highlight'>Quantity</span> </label> </div> </div> </div> <?php echo standardInputField('UoM Name/Pkg. Of:', 'pkg_of', $pkg_of, $errors); ?> <?php echo standardInputField('Price:', 'price', $price, $errors); ?> <?php echo standardInputField('Flyer Page #:', 'flyer_page', $flyer_page, $errors); ?> So then I decided to change the input type for that field to be a radio button, accepting one of two choices i.e. "UoM" or "Qty", and therefore I added the remainder of the code, whilst also commenting/remarking out the first statement. Now, what happens (when I added the radiobutton-related code above) is that control no longer goes into the TRUE portion/logic of the "if ( !empty($_POST))" condition-check - shown in the code below - but rather, it seems to go into the "ELSE/FALSE" portion of that conditional check. However, a record does get added to my table, even though I do not have an "INSERT INTO..." clause in the ELSE porition of that check. print_r($_POST); if ( !empty($_POST)) { // keep track of $_POST(ed) values by storing the entered values to memory variables $store_id = $_POST['store_id']; $item_id = $_POST['item_id']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; ... ... $sql = "INSERT INTO shoplist (store_id,item_id,qty_pkg,pkg_of,price,flyer_page,limited_time_sale,flyer_date_start,nos_to_purchase,section_id,shopper1_buy_flag,shopper2_buy_flag,purchased_flag,purchase_later_flag,no_flag_set) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $q = $pdo->prepare($sql); $q->execute(array($store_id,$item_id,$qty_pkg,$pkg_of,$price,$flyer_page,$limited_time_sale,$flyerDateStart,$nos_to_purchase,$section_id,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_Y)); } else { echo "<br />There's something wrong somewhere!!!<br />"; print_r ($_POST); $qty_pkg = ''; $pkg_of = '';; Thanks again.
  10. Hello All, I'm kinda new to PHP and web development and I seem to have a very wierd problem which is driving me nuts (for the last 2 days)...so I'd appreciate any and all help in getting it resolved. Okay, so here's the problem: In the code below, I used to have just the first statement below...which essentially accepted input as a textbox for a text field named qty_pkg (in the underlying MySQL table)...and that used to work just fine. So then I decided to change the input type for that field to be a radio button, accepting one of two choices i.e. "UoM" or "Qty", and therefore I added the remainder of the code, whilst also commenting/remarking out the first statement. What happens (when I added the radiobutton-related code) is that control no longer goes into the TRUE portion/logic of the "if ( !empty($_POST))" condition-check, but rather, it seems to go into the "ELSE/FALSE" portion of that conditional check. However, a record does get added to my table, even though I do not have an "INSERT INTO..." clause in the ELSE porition of that check. Also, what gets displayed on screen is as follows: ------------------------------------------------------------------------------------------------------------------------------------ Array() There's something wrong somewhere!!! Array() ------------------------------------------------------------------------------------------------------------------------------------ Now, if/when I comment/remark the radiobutton-related code, the "if ( !empty($_POST))" logic seems to work fine and the following is displayed on screen (which is what I expect): ------------------------------------------------------------------------------------------------------------------------------------ Array ( [datepicker] => 10/30/2014 [store_id] => 48 [new_store_name] => [item_id] => 5 [new_item_name] => [pkg_of] => 1 [price] => 1 [flyer_page] => 1 [limited_time_sale] => Array ( [0] => fri [1] => sat ) [nos_to_purchase] => 1 [create-and-add-more] => Create and Add More ) Notice: Undefined index: qty_pkg in /var/www/create.php on line 54 Array ( [0] => Array ( [item_id] => 5 [0] => 5 [item_name] => BD Cheese Strings [1] => BD Cheese Strings [section_id] => 7 [2] => 7 ) ) ------------------------------------------------------------------------------------------------------------------------------------ The other wierd thing is that if/when I now uncomment the first statement (which used to work just fine before) the "if ( !empty($_POST))" logic no longer seems to work the way it used to. Does/can someone see something wrong with my code somewhere? <!-- <?php echo standardInputField('Qty / Pkg', 'qty_pkg', $qty_pkg, $errors); ?> --> <div class="control-group"> <label class="control-label">Priced by:</label> <div class="priced-by-radio-container"> <div class="pb-radiobuttons-container"> <label class="indent-to-the-left"> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='UoM' $pb1> <span class='no-highlight'>Unit of Measure</span> </label> <label> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='Qty' $pb2> <span class='no-highlight'>Quantity</span> </label> </div> </div> </div> <?php echo standardInputField('UoM Name/Pkg. Of:', 'pkg_of', $pkg_of, $errors); ?> <?php echo standardInputField('Price:', 'price', $price, $errors); ?> <?php echo standardInputField('Flyer Page #:', 'flyer_page', $flyer_page, $errors); ?> print_r($_POST); if ( !empty($_POST)) { // keep track of $_POST(ed) values by storing the entered values to memory variables $store_id = $_POST['store_id']; $item_id = $_POST['item_id']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; ... ... $sql = "INSERT INTO shoplist (store_id,item_id,qty_pkg,pkg_of,price,flyer_page,limited_time_sale,flyer_date_start,nos_to_purchase,section_id,shopper1_buy_flag,shopper2_buy_flag,purchased_flag,purchase_later_flag,no_flag_set) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $q = $pdo->prepare($sql); $q->execute(array($store_id,$item_id,$qty_pkg,$pkg_of,$price,$flyer_page,$limited_time_sale,$flyerDateStart,$nos_to_purchase,$section_id,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_Y)); } else { echo "<br />There's something wrong somewhere!!!<br />"; print_r ($_POST); $qty_pkg = ''; $pkg_of = '';; Thanks.
  11. Hello JS experts, I'm new to JS coding (self-learning) and I have just one (potenitally) simple request to ask of you wonderful folks here. Oh BTW, I've tried searching through this forum (and the WWW as well) but couldn't seem to easily find something that fits my request, or was easy for me to understand and apply to my situation. So what I have/want is: a Data-Entry form which (for the first record/entry for a given date) allows the user to select a date from a "Calendar Date Picker". Upon subsequent records/entries (for the same date), the date field should no longer be accessible, but the (previously entered/selected) value should be both displayed (greyed-out) and certainly carried over to the DB/Table. I know this might be a very simple piece of code, but being that I'm a newbie, I'm not sure how to achieve this. Would appreciate any and all help to get this done (preferably the necessary code). If it helps, here's some of my existing code that's related to the field names: Form field details: <div class="control-group"> <label class='control-label'>Select Flyer Start Date:</label> <input type="text" name="datepicker" id="datepicker"> </div> DB (table) field details: $flyerDateStart = isset($_POST["datepicker"]) ? $_POST["datepicker"] : ""; Thanks much.
×
×
  • 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.