Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    28
    Thanks
    17
    Thanked 0 Times in 0 Posts

    using php to create a table

    Code:
    <table class="table">
    <tr ><td>Height/</br>Weight</td>
    <?php
    $NumRows = (($_GET["max_weight"] - $_GET["min_weight"])/4) - 1;
    
    for($i=$_GET["min_weight"];$i<=$NumRows;$i=$i+5){
    echo "<tr>";
    }
    	  
    ?>
    </table>
    well i have my input variables max_weight and min_weight for the rows. when i input values for these variables i want a weights column with min_weight value and then new rows which add 5 to the min_weight until the row max_weight is reached. example if i enter 50 for min weight and 80 for max weight my column would look like this
    50
    55
    60
    65
    70
    75
    80
    however im struggling to do this does anyone know how i can make my code work? after i do my rows, i can create the columns which has the same concept

    thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    These are all numeric?
    You don't need to concern yourself with calculating a row count. Simply iterate using a while.
    PHP Code:
    $iStep 5;
    // Get these
    $iMin 50;
    $iMax 80;

    $iCur $iMin;
    print(
    '<table class="table">');
    print(
    '<tr ><td>Height/</br>Weight</td>');
    while (
    $iCur <= $iMax)
    {
        
    printf('<tr><td>%d / %s</td></tr>'$iCur'Not sure what this is.');
        
    $iCur += $iStep;
    }
    print (
    '</tr>');
    print(
    '</table>'); 
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    nervousprogramm (03-14-2013)

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    28
    Thanks
    17
    Thanked 0 Times in 0 Posts
    <?php
    $iStep = 5;
    // Get these
    $iMin = $_GET["min_weight"];
    $iMax = $_GET["max_weight"];

    $iCur = $iMin;
    print('<table class="table">');
    print('<tr ><td>Height/</br>Weight</td>');
    while ($iCur <= $iMax)
    {
    printf('<tr><td>%d</td></tr>', $iCur);
    $iCur += $iStep;
    }
    print ('</tr>');
    print('</table>');

    ?>

    thanks for the help was wondering if these values where on different rows or on the same. (my webpage looks like its on one but the code shows its on different).
    Last edited by nervousprogramm; 03-14-2013 at 06:50 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I specified them on different rows with the use of the <tr> within the loop. It wasn't clear how you wanted them to be, but I mimicked the numbers you had there in plain text.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    nervousprogramm (03-14-2013)

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    28
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    I specified them on different rows with the use of the <tr> within the loop. It wasn't clear how you wanted them to be, but I mimicked the numbers you had there in plain text.
    Thanks

  • #6
    New Coder
    Join Date
    Oct 2012
    Posts
    28
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Im struggling to implement this logic into the column section heres my code below:


    Code:
    <?php
    $iStep = 5;
    
    // Get these
    $iweightMin = $_GET["min_weight"];
    $iweightMax = $_GET["max_weight"];
    $iheightMin = $_GET["max_height"];
    $iheightmax = $_GET["min_height"];
    
    $iCur = $iweightMin;
    $iCol = $iheightMin;
    print('<table class="table">');
    print('<tr ><td>Height/</br>Weight</td>');
    while ($iCur <= $iweightMax)
    {
        printf('<tr><td>%d</td></tr>', $iCur);
        $iCur += $iStep;
    }
    $rowiCol = $iheightMin;
    
    while ($iCol <= $iheightmax)
    {
    
       print('<td>%d</td>', $iCol);
       $iCol += $iStep;
    }
    
    
    print ('</tr>');
    print('</table>');  
    	  
    ?>
    any ideas

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Ah, I just copied the original table head you had. Its missing an </tr> on it.

    How is the height related to the width? This will create a single row with many columns in the last block, but HTML wise I'm not sure what that'll look like (I believe columns need to match in HTML).
    Should the be factored into the same row?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you original code doesn't output anything

    changed

    echo "<tr>";

    to

    echo "<tr><td>".$i."</td></tr>";

    PHP Code:

    <table class="table">
    <tr ><td>Height/</br>Weight</td></tr>
    <?php
    $NumRows 
    = (($_GET["max_weight"] - $_GET["min_weight"])/4) - 1;

    for(
    $i=$_GET["min_weight"];$i<=$NumRows;$i=$i+5){
    echo 
    "<tr><td>".$i."</td></tr>";
    }
          
    ?>
    </table>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    nervousprogramm (03-16-2013)

  • #9
    New Coder
    Join Date
    Oct 2012
    Posts
    28
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Im still trying to solve this problem lol heres my latest php code
    Code:
    <table class="table">
    <?php
    $MaxHeight=$_GET["max_height"];
    $MaxWeight=$_GET["max_weight"];
    for($i=$_GET["min_height"]; $i<=$MaxHeight;$i=$i+5){
    	echo '<tr>'.$i.'</tr>';
    	for($j=$_GET["min_weight"]; $j <=$MaxWeight; $j=$j+5) {
    		
        	
    			echo '<td class="cell1">'.$j.'</td>';
    		}
    		
    	}
    	echo '</tr>';
    
    ?>
    </table>
    im trying to get the columns and rows to increase by 5 and im trying to do a calculation using the x and y values but im really struggling lol and the first column im trying to add a title for the column and rows
    Last edited by nervousprogramm; 03-20-2013 at 12:46 AM.

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    How is it you are wanting this to look? Can you draw a table with html or ascii and show what it should look like as well as the MaxHeight and MaxWeight variable values?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    nervousprogramm (03-20-2013)

  • #11
    New Coder
    Join Date
    Oct 2012
    Posts
    28
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    How is it you are wanting this to look? Can you draw a table with html or ascii and show what it should look like as well as the MaxHeight and MaxWeight variable values?
    http://imageshack.us/photo/my-images/825/bmiq.png/

    also min height = 150 max height- 190

    min weight = 50 max weight 90

    also the equation im trying to do is weight/(Height*100)^2

  • #12
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    i can't make any sence of your calculation but based on it all my answers are 2

    PHP Code:
    <table class="table" border="1">
    <?php
    // testing values
    $i 0;
    $j 0;
    $_GET["min_height"] = 150;
    $_GET["max_height"] = 190;
    $_GET["min_weight"] = 50;
    $_GET["max_weight"] = 90;

    //weight/(Height*100)^2 
    echo '<tr><td>Weight/Height</td>';
    for(
    $j=$_GET["min_height"]; $j <=$_GET["max_height"]; $j=$j+5) {
            echo 
    '<td class="cell1">'.$j.'</td>
            '
    ;
        }
    for(
    $i=$_GET["min_weight"];$i<=$_GET["max_weight"];$i=$i+5){
        echo 
    '<tr><td>'.$i.'</td>
        '
    ;
        
        for(
    $j=$_GET["min_height"]; $j <=$_GET["max_height"]; $j=$j+5) {
        
    $k $i/($j*100)^2;           //      your calculation
            
    echo '<td class="cell1">'.$k .'</td>
            '
    ;
        }
        
        echo 
    '</tr>';
            
    }
        

    ?>
    </table>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #13
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    closest i can get is

    PHP Code:
    <table class="table" border="1">
    <?php
    // testing values
    $i 0;
    $j 0;
    $_GET["min_height"] = 150;
    $_GET["max_height"] = 190;
    $_GET["min_weight"] = 50;
    $_GET["max_weight"] = 90;

    //weight/(Height*100)^2 
    echo '<tr><td>Weight/Height</td>';
    for(
    $j=$_GET["min_height"]; $j <=$_GET["max_height"]; $j=$j+5) {
            echo 
    '<td class="cell1">'.$j.'</td>
            '
    ;
        }
    for(
    $i=$_GET["min_weight"];$i<=$_GET["max_weight"];$i=$i+5){
        echo 
    '<tr><td>'.$i.'</td>
        '
    ;
        
        for(
    $j=$_GET["min_height"]; $j <=$_GET["max_height"]; $j=$j+5) {
        
    $k $i/(($j*100)*($j*100));
            echo 
    '<td class="cell1">'.substr($k,0,6) .'</td>
            '
    ;
        }
        
        echo 
    '</tr>';
            
    }
        

    ?>
    </table>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    nervousprogramm (03-20-2013)


  •  

    Posting Permissions

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