PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table pincode ( ID int, pin_code int, district varchar(32), state char(2) ); insert into pincode (ID, pin_code, district, state) values (1, 123456, 'distname1', 'US'), (2, 123457, 'distname2', 'US'), (3, 123458, 'distname3', 'US'), (4, 123459, 'distname4', 'US'); create table table_alloted ( tech_id varchar(32), insert_dt date, pin_code int, district varchar(32), state char(2) );
Copy Clear
Copy Format Clear
<?php $con = &$pdo; $sqlInsert= $con->prepare( "INSERT INTO `table_alloted` (`tech_id `, `insert_dt`, `pin_code`, `district`, `state`) SELECT 'ts12563', '" . date('d-m-Y') ."', `pin_code`, `district`, `state` FROM `pincode` WHERE `state` = :state" ); $sqlInsert->execute(array( ':state' => 'US' )); $query = "SELECT * FROM `table_alloted`;"; $stmt = $pdo->prepare($query); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); print_r($rows);
Show:  
Copy Clear