Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008
    Location
    London, UK
    Posts
    154

    PHP - Table Lookup!?

    Hi Guys,
    This is a random project but i need some help!
    I have a table with 3 Variables "n" "p" and "x" anyone who used statistics will know this table

    I have attached a screen shot of a snippet of the data! (n value goes upto 25, only tables for n=1 and n=2 are shown)

    But I am looking to create a PHP script to look the results, so that in a HTML somebody enters the values for "n" "p" and "x" and hits a button, and out comes the number from the table!

    I played with PHP before, but I have no idea where to start for this!

    Any Ideas?

    Cheers
    Volkan
    Attached Thumbnails Attached Thumbnails untitled.JPG  
    EX Networks Limited (EXN)
    █ Enterprise Managed Services, VMware Cloud, Complex Hosting
    █ UK Datacentre Solutions, IP Transit, Layer 2 Services
    www.exn.uk - Call us on: +44 (0) 203 002 9259

  2. #2
    Join Date
    Feb 2003
    Location
    Canada
    Posts
    958
    Code:
    <?php
    # First array index is n with arrays holding p and x
    # Second array index is p converted to 0 padded integer (was originally trying to avoid decimals)
    # Third array is indexed numerically starting with 0 (since x = [0..n])
    
    $values = array(
                  1 => array(
                             '001' => array(0.99, 1),
                             '002' => array(0.98, 1),
                             '003' => array(0.97, 1),
                             '004' => array(0.96, 1)
                               )
                        # this would continue on and on and on for all values
                   );
    
    $n = is_int($_REQUEST['n']) ? $_REQUEST['n'] : null;
    $p = is_float($_REQUEST['p']) ? sprintf('%3d', $_REQUEST['p'] * 100) : null;
    $x = is_int($_REQUEST['x']) ? $_REQUEST['n'] : null;
    
    if (! is_null($n) && ! is_null($p) && ! is_null($x) ) {
      echo 'Number looked up is: ' . $values[$n][$p][$x];
    } else {
      echo "Invalid value(s) specified";
    }
    ?>
    
    <form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
    N: <input type="text" name="n" maxlength="2" size="3" /><br />
    P: <input type="text" name="p" maxlength="6" size="7" /><br />
    X: <input type="text" name="x" maxlength="2" size="3" /><br />
    <input type="submit" name="submit" value="Lookup" />
    </form>
    Untested but I'm more a Ruby guy than PHP
    Last edited by Adam-AEC; 01-23-2008 at 11:44 PM.

Posting Permissions

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