Jump to content

Search the Community

Showing results for tags 'for-loop'.

  • 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 2 results

  1. Hello everyone! I would like to need some help from someone who understands the basics of PHP. About the problem: I am supposed to make the user's input number multiple (a number between 0 and 10) with the text string the user has written. For example, the user writes "Hello" and "5", "Hello" should be printed out five times. I must use a for-loop and a while-loop to solve it.) Maybe it has to do with something called parameter. Would be thankful for some help! This is my current code: <form method="POST"> Message: <input type="text" name="message"/> Number: <input type="text" name="number"/> <input type="submit" value="OK!" name="submit" /> </form> <?php if(isset( $_POST["submit"] ) ) { $message = $_POST["message"]; $number = $_POST["number"]; ?> <?php for ($random = 0; $random < 10; $random = $random + $number) { echo "<ul><li>$message</li></ul>"; } ?> <?php } ?>
  2. I have extensively searched the web for this but haven't found anything that can help! At the moment I have three loops: // loop 1 finds the answers if(isset($_POST['qanswer'])){ ($question = $_POST['qanswer']); for($i=0; $i < count($question); $i++) { echo "POSTED ANSWERS" . $question[$i] . "<br/>"; } } else { echo '<p style="color: Red">No Answers POSTED!</p>'; } // loop 2 finds the comments if(isset($_POST['canswer'])){ ($comment = $_POST['canswer']); for($i=0; $i < count($comment); $i++) { echo "POSTED COMMENTS" . $comment[$i] . "<br/>"; } } else { echo '<p style="color: Red">No Comments POSTED!</p>'; } // loop 3 combines the answers and comments for($x = 0; $x < count($comment); $x++){ if(isset($question[$x])){ $question[$x] = $question[$x] . ' ' . $comment[$x]; } } $result = $question; // saves the answers and comments as a string ($result) Each comment[$i] is the same key and $question[$i]. Inserting into the table i have: $query = "INSERT INTO audit_data (Q4101, Q4102, Q4103, Q4104, etc...) VALUES '$result[0]','$result[1]','$result[2]','$result[3]','$result[4]', etc...)"; mysqli_query($link, $query) or die(mysqli_error($link)." Q=".$query); 1) is this the best way to go about this? 2) It is nearly working, i can get the $question and $comment into the first columns for instance: $result[0] to result[10] but if i try to insert further on in the table say $result[40] to $result[50] i only get the $question values and no $comment values. I have looked at array_map and preg_match on the manual but not sure how or which one to use. I don't want the table normalized and i am aware of injection problems.
×
×
  • 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.