www.webdeveloper.com
Results 1 to 3 of 3

Thread: is there a way to make this code short?

Threaded View

  1. #1
    Join Date
    Nov 2013
    Posts
    3

    Question is there a way to make this code short?

    hello,

    i'd like to have help here with my code here i don't know if theres a way but im trying to make a form exercises code like this
    http://www.englisch-hilfen.de/en/exe...le_present.htm

    and i tried my code so far i go this

    PHP Code:

    <?php
     

    $correctSolution1 
    'do';
    $correctSolution2 'do';
    ?>
    <form  method="post" autocomplete="off">
      


            <table align=left width="700px" bgcolor="#FFCC99" border="0" cellspacing="0" cellpadding="1">
            
              <tr>
                <td>
                  <table width="100%" bgcolor="#FFFFCC" cellspacing="4" cellpadding="1">
                  
                    </td>
                    </tr>
                    
                    <tr>
                        <td>
                            <table>
                            <?php


    if(isset($_POST['add']) == TRUE) {
        
       
        
        
    $solution1 $_POST['solution1'];
        
    $solution2 $_POST['solution2'];
        
       
        if(empty(
    $solution1) == TRUE) {
        if(empty(
    $solution2) == TRUE) {
            echo 
    '<td><span style="color: blue;">"unanswered"</span> you <span style="color: blue;">"unanswered"</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td></br>';
       return;
        }}
        if(empty(
    $solution1) == TRUE) {
        if (
    $solution2 == $correctSolution2) {
            echo 
    '<td>1)  <span style="color: blue;">"unanswered"</span> you <span style="color: green;">'.$solution2.'</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        if(
    $solution1 == $correctSolution1 ) {
        if(empty(
    $solution2) == TRUE) {
            echo 
    '<td>1)  <span style="color: green;">'.$solution1.'</span> you <span style="color: blue;">"unanswered"</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        if(
    $solution1 != $correctSolution1 ) {
        if(empty(
    $solution2) == TRUE) {
            echo 
    '<td>1)  <span style="color: red;">'.$solution1.'</span> you <span style="color: blue;">"unanswered"</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        if(empty(
    $solution1) == TRUE) {
        if (
    $solution2 != $correctSolution2) {
            echo 
    '<td>1)  <span style="color: blue;">"unanswered"</span> you <span style="color: blue;">'.$solution2.'</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        
        
       
        
        if(
    $solution1 == $correctSolution1 ) {
        if (
    $solution2 == $correctSolution2) {
            echo 
    '<td>1)  <span style="color: green;">'.$solution1.'</span> you <span style="color: green;">'.$solution2.'</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        if(
    $solution1 == $correctSolution1 ) {
        if (
    $solution2 != $correctSolution2) {
            echo 
    '<td>1)  <span style="color: green;">'.$solution1.'</span> you <span style="color: red;">'.$solution2.'</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        if(
    $solution1 != $correctSolution1 ) {
        if (
    $solution2 == $correctSolution2) {
            echo 
    '<td>1)  <span style="color: red;">'.$solution1.'</span> you <span style="color: green;">'.$solution2.'</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        
        
        if(
    $solution1 != $correctSolution1 ) {
        if (
    $solution2 != $correctSolution2) {
            echo 
    '<td>1)  <span style="color: red;">'.$solution1.'</span> you <span style="color: red;">'.$solution2.'</span> lemon?</td><td> <i>Correct answer: </i> <font color="006633"><b>Do</b></font> you <font color="006633"><b>drink</b></font> mineral water?</td> </br>';
        return;}}
        
        
        
        
        echo 
    '<tr><td><a href="' $_SERVER['HTTP_REFERER'] . '"><input type="button"  value="Repeat test" /></a></td></tr>';
        
    }

    else {

        
    ?>
                            
                            


                            
                                                                <tr><td  colspan="2">1) <input type="text"  name="solution1"  /> you <input type="text"  name="solution2"  /> mineral water? <b><i>(to drink)</i></b></td></tr>

                                                        </table>
                                                        
                        </td>
                    </tr>
                    
                    <tr><td height="1"><hr></td></tr>
                    <tr>
                      <td align="left"><input class="small_button" type="submit" name="add" value="Check" />
                      
                          <hr>
                          

    </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
                                                                  <?php
                                                            
    }

    ?>
    </form>
    as well i don't know how to make that button of show answers that gives answers without taking exercise

    any help
    Last edited by NogDog; 11-21-2013 at 10:28 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles