Jump to content

alco19357

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

Posts posted by alco19357

  1. HTML FORM

    <form action="" method="post">
    1<br>
    <input type="checkbox" value="3" name="cb1[]"><br>
    <input type="checkbox" value="6" name="cb1[]"><br>
    <input type="checkbox" value="8" name="cb1[]"><br><br>
    2<br>
    <input type="checkbox" value="1" name="cb2[]"><br>
    <input type="checkbox" value="2" name="cb2[]"><br>
    <input type="checkbox" value="3" name="cb2[]"><br>
    <input type="submit" value="calculate">
    </form>
    

     

    php

    $group1 = $_POST['cb1'];
    $group2 = $_POST['cb2'];
    //calculate group 1
    $group1_value = 0;
    for($i=0; $i<count($group1); $i++){
      $group1_value = ($group1[$i])+($group1_value);
    }
    
    //calculate group 2
    $group2_value = 0;
    for($q=0; $q<count($group2); $q++){
      $group2_value = ($group2[$q])+($group2_value);
    }
    
    //multiply group 1 and 2
    $end_value = $group1_value*$group2_value;
    
    echo "End Value = ".$end_value;
    

     

    How bout something like that?

     

  2. yes or to save constants you can do an array

     

    $databaseInfo = array(
      "host"  =>  "localhost",
      "user"  =>  "myuser",
      "pass" =>  "password",
      "db"  =>  "database",
      "pconn"  =>  false,
      "store_sess"  =>  ""
    );
    

     

    Then add an include 'config.php'; to each page and just use this where needed

    $databaseInfo["host"], etc.

  3. <?php
    
      $sql = "SELECT foo FROM bar";
      $result = mysql_query($sql);
    
      // check your call to mysql_query succeeded.
      if ($result) {
        // check $result holds data
        if (mysql_num_rows($result)) {
          // in here it is safe to use $result to display data
          while ($row = mysql_fetch_assoc($result) {
            echo $row['foo'] . "<br />";
          }
        } else {
          // no data found.
        }
      } else {
        // query failed, handle error.
      }
    
    ?>
    

     

    $sql = "Select * from links where user_id = 'Addidas'";
    $records = mysql_query($sql);
    $records_count = mysql_num_rows($records);
    
    if($records_count > 0){
      //do functions
    }else{
      //parse error
    }
    

     

    For this you can check if there is a specific number of returns for instance if($records_count === 1){ and so on

×
×
  • 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.