need help please

Discussion in 'PHP' started by MrPJH, Apr 10, 2012.

  1. #1
    
    <?php
    include("include/config.php");
    $sql=dbFetchArray(dbQuery("SELECT * FROM table_from"),MYSQL_BOTH);
    $sql1=array($sql);
    
    $a = stripslashes($sql['a']);
    $b = stripslashes($sql['b']);
    $c = base64_decode(stripslashes($sql['c']));
    $md5pass = md5(['d']);
    $e = stripslashes($sql['e']);
    $f = stripslashes($sql['f']);
    $g = stripslashes($sql['g']-1);
    $h = stripslashes($sql['h']);
    $i = stripslashes($sql['i']);
    $j = '1';
    
    dbQuery("insert into table_to(a, b, c, d, e, f, g, h, i, j, k) values('$a','$b','$md5pass','$c','$d','1','$e','$f','$g','$h','$i')");
    ?> 
    
    PHP:
    this script copies one record from "table_from" to "table_to"

    there are more then 1000 records how can i copy all from table_from to table_to
     
    MrPJH, Apr 10, 2012 IP
  2. startdream

    startdream Member

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    28
    #2
    You can use foreach loop or while loop for $sql1
     
    startdream, Apr 10, 2012 IP
  3. MrPJH

    MrPJH Well-Known Member

    Messages:
    1,066
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    155
    #3
    i do it as
    
    $i=$sql1;
    // while($i<='1')
    while($i<=1)
      {
    dbQuery("insert into table_to(a, b, c, d, e, f, g, h, i, j, k) values('$a','$b','$md5pass','$c','$d','1','$e','$f','$g','$h','$i')");
    ?>
      $i++;
      }
    
    PHP:
    it do not take any action and do not give any error "script runs without error but no results"
     
    MrPJH, Apr 11, 2012 IP
  4. Atif123

    Atif123 Active Member

    Messages:
    576
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    90
    #4
    check your while loop condition. I think there is problem in it
     
    Atif123, Apr 11, 2012 IP
  5. MrPJH

    MrPJH Well-Known Member

    Messages:
    1,066
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    155
    #5
    maybe but not sure where
    i put it while($i<=1) then it copies 1 record from one table to two and while trying for second record it says "Duplicate" echoing copied record
    it means my while loop tries to copy same record again
     
    MrPJH, Apr 11, 2012 IP