Jump to content

Search the Community

Showing results for tags 'forloop'.

  • 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 (Dreamweaver, Zend, 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 3 results

  1. NOTE - Please read the information first as it contains important information to understand the problem. Rules → • There are 9 Columns(C1,C2,C3,C4,C5,C6,C7,C8,C9) [ Max columns will be 9] • The number of Rows can vary from 3,6,9,12,15,18 (Max). In this case Number of Rows shall be 12 Number of Rows = No of Tickets (Max Allowed 6) x Rows Per Ticket (Max Allowed 3). Thus, Max Rows can be 18 • Each Row is required to have 4 Blank Spaces and 5 Filled with Numbers • All numbers available in the Column Array have to be utilized • This configuration of an shall create a matrix of 9 Columns & 12 Rows (3 x 4 Tickets), which is 108 MATRIX BLOCKS where only a maximum of 60 numbers can be filled out of 108 available blocksrandomly with the above conditions being met 100%. • The numbers in column must be arranged / sorted in ASCENDING ORDER (For coding logic purpose, as soon as the number is assigned to the new MATRIX MAP use array_shift() or unset() the number so as to avoid repetition Example - Row 1 and Column 1 shall generate a MATRIX BLOCK - R1C1 Row 3 and Column 7 shall generate a MATRIX BLOCK - R3C7 Matrix Block can also be termed as Matrix Cell for your ease (if needed) MASTER SET OF ARRAY WITH NUMBERS array( "C1"=> array( 1, 2, 3, 5, 6, 7, 9 ), //7 Numbers "C2"=> array( 13, 14, 15, 17, 18, 19 ), //6 Numbers "C3"=> array( 21, 22, 23, 24, 25, 26, 30 ), //7 Numbers "C4"=> array( 31, 33, 34, 36, 37, 38, 39 ), //7 Numbers "C5"=> array( 41, 42, 46, 47, 48, 49, 50 ), //7 Numbers "C6"=> array( 51, 52, 53, 54, 55, 57, 58 ), //7 Numbers "C7"=> array( 61, 62, 64, 65, 69, 70 ), //6 Numbers "C8"=> array( 71, 74, 75, 76, 77, 78 ), //6 Numbers "C9"=> array( 82, 83, 85, 87, 88, 89, 90 ) //7 Numbers ); The above array has 60 Numbers to be filled out of 108 MATRIX BLOCK / CELL which meets the condition that for a FULL BLOCK containing 4 MINI BLOCKS WITH 3 ROWS (max. allowed) EACH I have been able to generate this without any issue meeting all the conditions of the Columns My Allocation Matrix Array will look like array( "R1"=> array( "C1"=> true, // Means that MATRIX BLOCK R1C1 will be NOT EMPTY "C2"=> false, // Means that MATRIX BLOCK R1C2 will be EMPTY "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> false ), "R2"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> false ), "R3"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> false, "C8"=> false, "C9"=> true ), "R4"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> false ), "R5"=> array( "C1"=> false, "C2"=> false, "C3"=> false, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> true ), "R6"=> array( "C1"=> true, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R7"=> array( "C1"=> false, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R8"=> array( "C1"=> true, "C2"=> false, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R9"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R10"=> array( "C1"=> false, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> false, "C9"=> false ), "R11"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> true, "C9"=> false ), "R12"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ) ); In the above array R stands for Row, C for Column, TRUE/FALSE (Boolean) means that if TRUE a Number can be filled in the resulting MATRIX BLOCK / CELL ( Row[Number]Column[Number] ) else if FALSE the MATRIX BLOCK / CELL shall be EMPTY The result for the above shall be PROBLEM : I am unable to understand what should possibly be the logic & loop used here for creating a MATRIX ALLOCATION MAP as shown above I have tried while, foreach & for but unable determine the perfect combination which would meet the conditions. (Tried all of the above with Nested Loops also)
  2. for starters, i am a complete beginner at PHP, so i know almost nothing. so, the basic outline is that i am required to create a table with 2 columns, and use PHP where i can so the first set of code lays down the table and the ability to type in text of "name" and "surname". ----i think this "input" is HTML, yes?? is there a way to enter it as PHP? <table border=\"2\"> <tr><th><b>Requirements</b></th><th><b>Selections</b></th></tr> <tr><td>Name</td><td><input type="text" name="name"/></td></tr> <tr><td>Surname</td><td><input type="text" name="surname"/></td></tr> so, for this next section, adding on is the part for "age". i want this to appear as a dropdown selection. i've written PHP where possible, however this does not work when opening the file in a browser. it simply leaves a blank dropdown menu with no options. ???? <tr><td>Age</td><td><select> <?php for ($num=11; $num<=22; $num++){ echo '<option>' .$num. '</option>'; } ?> </select> lastly, i have the part for "activity choice". this again i believe i wrote the radio buttons in HTML??? am i able to write this as PHP???? <tr><td>Activity Choice</td><td><input type="radio" name="activityChoice" value "music"/> Music ($30.00)<br> <input type="radio" name="activityChoice" value "swimming"/> Swimming ($25.50)<br> <input type="radio" name="activityChoice" value "tennis"/> Tennis ($20.00)<br> <input type="radio" name="activityChoice" value "basketball"/> Basketball ($15.50)<br> <input type="radio" name="activityChoice" value "netball"/> Netball ($15.50)<br> <input type="radio" name="activityChoice" value "dance"/> Dance ($10.50)<br> <input type="radio" name="activityChoice" value "communityService"/> Community Service (No Charge)</td></tr> please please please help??
  3. I am creating a quiz builder as part of an exercise. It allows the user to make a multiple choice quiz. They will be able to add a title, choose the number of questions they want and how many options they want for each question by inputting the values into a html form (all questions will have the same number of options). The code I have made for this is: <form method="post" action="quiz_form.php"> Quiz name<br/><input type="text" name="name" value="" maxlength="" /><br/> Choices<br/><input type="text" name="choices" value="" maxlength="3" /><br/> Questions<br/><input type="text" name="questions" value="" maxlength="3" /><br/> <input type="submit" name="submit" value="SUBMIT" /> </form> The next part of the quiz maker is to generate the html for the quiz and allow the user to input their questions in to that HTML. The code I have made for this is: if (isset($_POST['submit'])) {//form submitted $errors = array(); if (isset($_POST['choices'])) {//Number of choices per question if (is_numeric($_POST['choices'])) {//it is a number if (strlen($_POST['choices']) <= 3) {//there are no more than three charaters $choices = $_POST['choices']; } else {//add to errors array $errors[] = "<b>CHOICES: </b>You may only go upto 999 questions"; } } else {//add to errors array $errors[] = "<b>CHOICES: </b>Must be a number"; } } else {//add to errors array $errors[] = "<b>CHOICES: </b>Select number of choices"; } if (!empty($_POST['name'])) {//quiz name added $quizname = $_POST['name']; } else {//add to errors array $errors[] = "<b>Quiz name: </b>Add quiz name"; } if (isset($_POST['questions'])) {//number of questions specified if (is_numeric($_POST['questions'])) {//it is a number if (strlen($_POST['questions']) <= 3) {//there are no more than three charaters $questions = $_POST['questions']; } else {//add to errors array $errors[] = "<b>QUESTIONS: </b>You may only go upto 999 questions"; } } else {//add to errors array $errors[] = "<b>QUESTIONS: </b>Must be a number"; } } else {//add to errors array $errors[] = "<b>QUESTIONS: </b>Select the number of questions"; } if (empty($errors)) {//display choices if(isset($questions) && isset($choices)){//choices and question number selected echo "<h1>Change the values in each box</h1>\n";//headline echo "Quiz title: " . $quizname; //users quiz title echo "<form method=\"post\" action=\"addToDb.php\">\n";//start form for($q = 1; $q <= $questions; $q++){//loop through number of questions required echo " <input name='questions[]' type='text' value='question $q' /><br/>\n"; for($opt = 1; $opt <= $choices; $opt++){//loop through number of options required echo " <input name='choice[]' type='text' value='option $opt' /><br/>\n"; } } echo " <input name='submit' type='submit' value='SUBMIT' />\n";//submit form echo "</form>";//close form } } else {//echo errors foreach ($errors AS $v) { echo $v . "<br/>"; } } } else {//end $_POST['submit'] echo "fill out form"; } Finally I am trying to show what the user has created (This is where my first problem arises!). The code I have made for this is: if(isset($_POST['questions']) && isset($_POST['choice'])){ $q = $_POST['questions']; $c = $_POST['choice']; foreach($q AS $v){ echo $v . "<br/>\n"; foreach($c AS $value){ echo " " . $value . "<br/>\n"; } } }else{ echo 'not set'; } When I run the above program I get a problem at the final stage. That problem is that the options do not seem to be linked to the questions i.e. What I expect (Assuming 2 questions and 2 options are chosen): question 1 option 1 option 2 question 2 option 1 option 2 What I get (Assuming 2 questions and 2 options are chosen): question 1 option 1 option 2 option 1 option 2 question 2 option 1 option 2 option 1 option 2 a previous answer has suggested using the count() function and I have tried putting that advice into practice, but cant without success. I have considered using sessions, but I am sure that sessions would not be the right way to go. I assume that the loop is not linking the questions and choices array together for some reason and need to work out a way to get the code to link the two in order to get the output I expect. Please can someone tell me what I am missing. PS I know there are security problems at the moment, and will address them once I can complete the basics of this task.
×
×
  • 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.