This topic is locked
[SOLVED]

 insert sql query

11/13/2012 10:49:27 AM
PHPRunner General questions
C
chrispa author

Hi i use following
$str ="SELECT * FROM 28";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

echo $data["month"];

$strSQLInsert = "insert into restinghoursheetchild (date1,connect1) values ('".$data["month"]."','".$data["connect1"]."')";

db_exec($strSQLInsert,$conn);
but does not insert all records from table 28 but only one record
can you help

C
cgphp 11/13/2012

You need a loop:

global $conn;

$str ="SELECT month,connect1 FROM 28";

$rs = db_query($str,$conn);

while($data = db_fetch_array($rs))

{

$strSQLInsert = "insert into restinghoursheetchild (date1,connect1) values ('".$data["month"]."','".$data["connect1"]."')";

db_exec($strSQLInsert,$conn);

}
C
chrispa author 11/13/2012



You need a loop:

global $conn;

$str ="SELECT month,connect1 FROM 28";

$rs = db_query($str,$conn);

while($data = db_fetch_array($rs))

{

$strSQLInsert = "insert into restinghoursheetchild (date1,connect1) values ('".$data["month"]."','".$data["connect1"]."')";

db_exec($strSQLInsert,$conn);

}



thanks you very much is working !!!!!!