SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need some assistance.

    Hey all, new to php wondering if you could give me a hand with this that i have to accomplish.

    Create a page called lab1.php
    In lab1.php, create a Form with the following inputs:
    Dropdown with options from 1 to 10, labeled “Rows:”, Another Dropdown with options from 1 to 10, labeled “Columns:”,Submit button
    The form should submit values to “table.php” using the GET method
    Create a page called table.php
    In table.php, read the values submitted from lab1.php by referencing the appropriate indexes in the $_GET array.
    In table.php, construct a table that has:The amount of rows entered in part 2a, The amount of columns entered in part 2b
    Your first name in every ODD cell(1,3,5,7...) . Your name can be a string literal
    Ex: <td>JOHN</td>

    I have the html structure.

    HTML Code:
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title></title>
        </head>
       <body>
        <form action="table.php" method="GET">
        
        Rows: <select name="Rows">
        <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                </select>
                <br />
                
                Columns: <select name="Columns">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                </select>
                <br />
                <input type="submit" name="submit" value="Submit"/>
        </form>
    Last edited by ServerStorm; Feb 1, 2013 at 16:28. Reason: wrap code in [code][/code] or [html][/html] or [php][/php]

  2. #2
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This seems to work:

    PHP Code:
    <?php
      $rows 
    $_GET['Rows'];
      
    $columns $_GET['Columns'];
      
      echo 
    '<table border="1" style="border-collapse:collapse;">';
      
    $i 1;
      while(
    $i <= $rows) {
       
    $c 1;
       echo 
    '<tr>';
       while(
    $c <= $columns){
        echo 
    '<td>Row: '.$i' - Col: ' .$c.'</td>';
        
    $c++;
       }
       echo 
    '</tr>';
       
    $i++;
      }
      echo 
    '</table>';
    ?>
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  3. #3
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 2ndmouse View Post
    This seems to work:

    PHP Code:
    <?php
      $rows 
    $_GET['Rows'];
      
    $columns $_GET['Columns'];
      
      echo 
    '<table border="1" style="border-collapse:collapse;">';
      
    $i 1;
      while(
    $i <= $rows) {
       
    $c 1;
       echo 
    '<tr>';
       while(
    $c <= $columns){
        echo 
    '<td>Row: '.$i' - Col: ' .$c.'</td>';
        
    $c++;
       }
       echo 
    '</tr>';
       
    $i++;
      }
      echo 
    '</table>';
    ?>

    this does in fact work! but i need it to out my my name in every odd cell.. thanks for you help in advanced!

  4. #4
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    <?php
      $rows 
    $_GET['Rows'];
      
    $columns $_GET['Columns'];
      
      echo 
    '<table border="1" style="border-collapse:collapse;">';
      
    $i 1;
      
    $name 'name';
      while(
    $i <= $rows) {
       
    $c 1;
       echo 
    '<tr>';
       while(
    $c <= $columns){
       if (
    $c%&& $i+1%2) {
        echo 
    '<td>'.$name.'</td>';
        }else{
            echo 
    '<td>----</td>';
        }
        
    $c++;
       }
       echo 
    '</tr>';
       
    $i++;
      }
      echo 
    '</table>';
    ?>
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  5. #5
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are a LIFE SAVER. Not only do i understand now, you solved my problem. Thank you a TON

  6. #6
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2ndmouse, this did help me out a lot, but however, is there anyway to make the output in the odd cells. as of now it outputs in just every other row i feel, where as im trying to get it to output in cell 1,3,7,5 etc. thank you!

  7. #7
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OH!

    when I run that code it doesn't skip any rows - can you show me an image of the output?
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  8. #8
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I see:

    grid.png
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  9. #9
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I see what you mean now - get back to you later
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  10. #10
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 2ndmouse View Post
    Yes, I see what you mean now - get back to you later
    Okay thank you so much for you help!

  11. #11
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can not figure it out for the life of me...it really bugging me.

  12. #12
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by billboodnae View Post
    I can not figure it out for the life of me...it really bugging me.
    I think this is it:

    PHP Code:
    <?php
      $rows 
    $_GET['Rows'];
      
    $columns $_GET['Columns'];
      
    $row 1;
      
    $cell_no 1;
      
    $name 'name';  
      echo 
    '<table border="1" style="border-collapse:collapse;">';
      while(
    $row <= $rows) {
           
    $c 1;   
           echo 
    '<tr>';
           while(
    $c <= $columns){
               if (
    $cell_no%2) {
                  echo 
    '<td>'.$cell_no.$name.'</td>';
               }else{
                  echo 
    '<td>'.$cell_no.'----</td>';
               }
               
    $c++;
               
    $cell_no++;
           }
           echo 
    '</tr>';
           
    $row++;
      }
      echo 
    '</table>';
    ?>
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  13. #13
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    P.S. it would be interesting to know what use you put this solution to. Thanks
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.


Bookmarks

Posting Permissions

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