Jump to content

saviola

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Posts posted by saviola

  1. Hi all,

     

    i'm  a little confused. I try to doing some bitwise manipulations, but came across the following strange phenomenon:

    I try to do something like this :

    $x = 1;
    $x = $x >> 31;
    echo $x * pow(2,4);
    

     The output is 0 

    and

    $x = 1;
    $x = $x >> 33;
    echo $x * pow(2,4);
    

     The output is 0 

    but

    $x = 1;
    $x = $x >> 32;
    echo $x * pow(2,4);
    

     The output is 16 

     

    I am not very familiar with bit operations :-[, so can anyone help with some expolanation?

     

    Thanks advance!

     

    P.S. OS Win Xp 32bits , PHP Version 5.2.13

  2. Also can try this :

     

    function cleanData(&$str) {
    
      $str = preg_replace("/\t/", "\\t", $str);
      $str = preg_replace("/\r?\n/", "\\n", $str);
    
      if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
    
    }
    // file name for download
    $filename = "website_data_" . date('Ymd') . ".xls";
    
    header("Content-Disposition: attachment; filename=\"$filename\"");
    header("Content-Type: application/vnd.ms-excel");
    
    $flag = false;
    
    // execute the query
    $result = mysql_query("SELECT * FROM tableName ORDER BY columnName") or die('Query failed!');
    
    while(false !== ($row = mysql_fetch_assoc($result))) {
      if(!$flag) { // display field/column names as first row
        echo implode("\t", array_keys($row)) . "\n";
        $flag = true;
      }
      array_walk($row, 'cleanData');
      echo implode("\t", array_values($row)) . "\n";

    }

  3. Thanks, that figures.

     

    I actually want to select more data from the database based on the $id values.

     

    What would be the best way to write the data retrieved to excel?

     

    Maybe something like this :

    if($_POST["submitMyForm"]) {
      $checked = implode(", ", $_POST["cb"]);
      echo $query = "SLECT * FROM table WHERE id IN($checked)";
    
    }

     

    <form id="myform"  method="POST" action="">
    
    <input type="checkbox" name="cb[]" value="1">
    <input type="checkbox" name="cb[]" value="2">
    <input type="checkbox" name="cb[]" value="3">
    <input type="checkbox" name="cb[]" value="4">
    <input type="checkbox" name="cb[]" value="5">
    <input type="submit" name="submitMyForm" value="Export">
    </form>

  4. $childNum = array();
    
    function getPar($array, &$childNum) {
    
    
      foreach ( $array as $key => $value ) {
    
        if( $value['parent'] ) {
    
          if ( !isset($childNum[$value['parent']]) || !$childNum[$value['parent']] ) {
    
            $childNum[$value['parent']] = 1;
          } else {
    
            $childNum[$value['parent']]++ ;
          }
        }
      }
      return $childNum;
    }
    
    
    print_r(getPar($arr, $childNum));

  5. I saw also this spelling error. Shouldn't be

    $tbl_namer=cpdUsr;
    

    , because in

    // Insert data into database
    $sql="INSERT INTO $tbl_name(confirm_code, username, password)VALUES('$confirm_code', '$myusername', '$mypassword')";
    $result=mysql_query($sql);

    you use

     $tbl_name

  6. I'm not sure, but i think the problem comes from the fact you're not define a variable $error at the beginning of the script.

    When there are no mistakes, it does not exist (not defined), and you do check whether it is an array.

    Define the variable $error at the beginning of the script :

    ....
    .....
    //but if they do not, this code simulates magic quotes
    if( !get_magic_quotes_gpc() )
    {
        if( is_array($_POST) )
            $_POST = array_map('addslashes', $_POST);
    }
    $error = array();
    ...........
    ..........
    

     

    and verification changes of :

    .....
    .....
    //we need to make sure the order total was calculated before using the submit button
    if( empty($_POST["Amount_To_Pay"]) )
        $error["no_qty"] = "Please go back and calculate your order total and resubmit.";
    
    if(count($error) )
    {
    
      echo "An error occurred while processing your order.";
    .......
    .......
    

  7. If you name your form elements color[] you will end up with an array within $_POST['color']. You can then easily loop through this array and do your inserts.

     

    This is will be something like  that :

    <form method="POST" action="index.php" >
      1: <input type="checkbox" name="cid[]" value="1">
      2: <input type="checkbox" name="cid[]" value="2">
      3: <input type="checkbox" name="cid[]" value="3">
      4: <input type="checkbox" name="cid[]" value="4">
      5: <input type="checkbox" name="cid[]" value="5">
      6: <input type="checkbox" name="cid[]" value="6">
      <input type="submit" name="GO">
    </form>
    
    <?php
    if($_POST["GO"]) {
        $cid = $_POST["cid"];
      	foreach ( $cid as $id ) {
      echo "<br>".$id;
            }
    }
    ?>
    

     

    The SQL query can be generated on this way :

    $checkedColors = "('".implode("'),('", $cid)."')";
    
    $sql = "INSERT INTO `mytable` (colors) VALUES $checkedColors";
    

     

    [attachment deleted by admin]

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