Jump to content

Search the Community

Showing results for tags 'looping'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 5 results

  1. My longest post of the year..... (thank you in advance for scrolling šŸ˜€) Here is what my $_POST array looks like using print_r($_POST) Array ( [newQuantity77777] => 3 [newPrice77777] => 5.00 [usedQuantity77777] => 1 [usedPrice77777] => 3.99 [total77777] => 18.99 [newQuantity88888] => // sometimes empty [newPrice88888] => [usedQuantity88888] => 4 [usedPrice88888] => 12.00 [total88888] => 48.00 [newQuantity44444] => 2 [newPrice44444] => 4.00 [usedQuantity44444] => 0 [usedPrice44444] => 3.99 [total44444] => 8.00 // these values I don't need [date] => July 25 2021 // these values below I don't need [address] => 123 Anystreet Avenue [address2] => [zipcode] => 90210 [city] => Beverly Hills [state] => CA [planet] => Mars ) I've been trying to use that array to create a special "sub-array" for only the SKU numbers and just their new and used quantities and prices. DESIRED RESULT: Array ( [77777] => Array ( [newQuantity] => 3 [newPrice] => 5.00 [usedQuantity] => 1 [usedPrice] => 3.99 ) [88888] => Array ( [newQuantity] => 0 [newPrice] => 0 [usedQuantity] => 4 [usedPrice] => 12.00 ) [44444] => Array ( [newQuantity] => 2 [newPrice] => 4.00 [usedQuantity] => 0 [usedPrice] => 3.99 ) ) Knowing that my SKU numbers are always exactly 5 digits, and no other $_POST keys will ever have 5 digits, I've been able to accomplish this with horribly convoluted and unsatisfactory code like this: $sku = array(); foreach($_POST as $var => $val) { $number = substr($var,-5); if (preg_match("/\d{5}/",$sku)) { $sku[$number] = // the array keys will be the SKU numbers // then I keep looping to look for the string "newQuantity" // capture that value... and create little mini arrays // for my big multidimensional array..... Is there a better way to go about this? Thank you.
  2. Hi there, so I'm having a little trouble understanding looping and arrays or inputs. I'm a Pshell programmer and things are done MUCH differently lol So heres the script I've created. <?php $first=400; $second=300; for ($i = $first; $second < $i; $i++) { echo $i; } ?> What I'm trying to accomplish is taking the first Number and the second and get it to count or "loop" up to 400 from the lower number. Then have it output the result. I'm not sure what I'm doing wrong here though......
  3. Hello fellow PHP developers. I have been stuck on a problem I just can not figure out. I am developing a couple forms (insert and update) that users fill out. On this form is general user information (first and last name fields, etc.) as well as a checkbox group based on an available ā€œgroupsā€ table. When the user fills out the form and makes their checkbox selections I write the user information to a user table, and write the userā€™s checkbox choices to a user_group_xref table (unique_id, fk_user_id, fk_group_id) for as many choices as the user selected. The fk_user_id is a foreign key to the user table, and the fk_group_id is a foreign key to the group table. User_table Unique_id, first_name, last_name, address Groups_table Unique_id, group_description, active_flag User_group_xref table Unique_id, fk_user_id, fk_group_id This all works correctly for the insert, and I can make the selections out of the tables no problem. To get the users previous selections, I query the xref table and join it back to the group table for the description. My user_groups query returns g.unique_id, g.group_description for the appropriate user. I generate the checkboxes with the following code: <?php do { ; ?> <br /> <label> <input type="checkbox" name="admin_groups[]" value="<?php echo $row_groups['pkID']; ?>" id="admin_groups_<?php echo $row_groups['pkID']; ?>" tabindex="<?php echo $iTabIndexCounter;?>" /> <?php echo $row_groups['group_description']; ?> </label> <?php } while ($row_groups = mysql_fetch_assoc($groups)); ?> This works fine in generating the checkboxes. How do I at the same time check those checkboxes previously selected? The only thing I can think of is to show only those checkboxes actually selected, but I want all checkboxes displayed, and those previously selected checked. Any suggestions would be greatly appreciated.
  4. Hello - I'm creating a source code generator and have the following code that loops over an array that creates an object. I want to add a , (comma) to the end of each iteration. Here's what the final output should look like: I have everything generating successfully but adding the , (comma) at the end of each item in the object. var rules1 = { 'fullName' : { required: true }, 'username' : { required: true, email: true }, 'password' : { required: true, minlength: 6, maxlength: 20 } }; How would I iterate over the object and add that comma? Also notice that the last item doesn't have a comma. Here's the source code I have to build the object: var rulesArray = []; $(".InputRulesSection").each(function () { $('.rulesTable').each(function () { var ruleInputName = $('.fieldNameInput', this).val(); var minLength = $('.minLengthInput', this).val(); var maxLength = $('.maxLengthInput', this).val(); var email = $(".email", this).attr("rel"); rulesArray.push( { ruleInputName:ruleInputName, minLengthInput:minLength, maxLengthInput:maxLength, email:email } ); }); }); return rulesArray; Here's the code I have to iterate over the newly created object: for (var i in rulesArray) { var ruleInputVal = rulesArray[i].ruleInputName; var email = rulesArray[i].email; var minLength = rulesArray[i].minLengthInput; var maxLength = rulesArray[i].maxLengthInput; rulesCode += "\t\t '" + ruleInputVal + "' : { \n "; rulesCode += "\t\t\t required: true" + addComma + "\n "; if (email == "email") { rulesCode += "\t\t\t email: true" + addComma + " \n "; } if (minLength > 0) { rulesCode += "\t\t\t minLength: " + minLength + addComma + " \n "; } if (maxLength > 0) { rulesCode += "\t\t\t maxLength: " + maxLength + addComma + " \n "; } rulesCode += "\t\t } \n"; } And finally, here's what I currently generate using the above code: Notice there aren't any commas after each item and keys? That's what I'm stumped on... how to approach it? Any help would be great. Thank you! var rules = { 'username' : { required: true email: true minLength: 6 maxLength: 20 } 'password' : { required: true minLength: 6 maxLength: 20 } };
  5. trying to write a code that will repeat a name until it gets to the number on the database. Database Information Name Number Mike 2 Oscar 2 Robert 1 Wanted to look like Full Name Mike Mike Oscar Oscar Robert Here is my Code <?php $result = mysql_query("SELECT * FROM `people`"); echo "<table border='1'> <tr> <th>Full Name</th> <th> </th> </tr>"; for ($i = 1 , $row = mysql_fetch_array($result) ; $i <= $row['Number'] ; $i++ ) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td> </td>"; echo "</tr>"; } echo "</table>"; ?> When i run the code it will only show the result like this Full Name Mike Mike and when i put the "for" again in the bottom of the first one it will show like this Full Name Mike Mike Oscar Oscar <?php $result = mysql_query("SELECT * FROM `people`"); echo "<table border='1'> <tr> <th>Full Name</th> <th> </th> </tr>"; for ($i = 1 , $row = mysql_fetch_array($result) ; $i <= $row['Number'] ; $i++ ) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td> </td>"; echo "</tr>"; } for ($i = 1 , $row = mysql_fetch_array($result) ; $i <= $row['Number'] ; $i++ ) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td> </td>"; echo "</tr>"; } echo "</table>"; ?> i need something to repeat "For" until it finishes all the Names
×
×
  • 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.