how do i input into 2 different table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sepetskill
Forum Newbie
Posts: 1
Joined: Mon Dec 23, 2013 1:59 am

how do i input into 2 different table

Post by sepetskill »

how do i input to a different table. Given 2 existing tables.

Code: Select all


<?php
$dbhost = 'localhost'; 
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass); //database connection



if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}




$sql=   "INSERT INTO staf_tidak_hadir
		SELECT b.No_Pekerja, b.Nama_Staf, b.Kod_Jawatan,b.Nama_Jawatan,b.Kod_PTJ,b.Nama_PTJ,b.Taraf_Jawatan,b.Status_Lantikan,b.Kategori_Staf
        FROM data_asas_staf_table a, staf_hadir b
        WHERE a.No_Pekerja = b.No_Pekerja";
		

		

mysql_select_db('sistem_statistic');


$list = array();
while($row=mysql_fetch_assoc($sql, MYSQL_ASSOC)){
     
    $list[] = row;
	if ($row['No_Pekerja']=;)
	
	
}







$retval = mysql_query( $sql, $conn );

if( !$retval )
	{
 	 die('Could not get data: ' . mysql_error());
	}

while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
	{
	echo"No Pekerja	   :{$row['No_Pekerja']}  <br> ".
      	"Nama Staf 	   :{$row['Nama_Staf']} <br> ".
     	"Kod Jawatan   : {$row['Kod_Jawatan']} <br> ".
        "Nama Jawatan  : {$row['Nama_Jawatan']}<br>".
	  	"Kod PTJ	   : {$row['Kod_PTJ']}<br>".
	  	"Nama PTJ	   : {$row['Nama_PTJ']}<br>".
	  	"Taraf Jawatan : {$row['Taraf_Jawatan']}<br>".
	 	"Staus Lantikan: {$row['Status_Lantikan']}<br>".
	 	"Kategori Staf : {$row['Kategori_Staf']}<br>";


}


mysql_close($conn);
?>








User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how do i input into 2 different table

Post by Celauran »

You would at the very least need to specify which columns these values are to be inserted into and then actually execute the query.
uday.strad
Forum Newbie
Posts: 10
Joined: Wed Oct 02, 2013 1:03 am

Re: how do i input into 2 different table

Post by uday.strad »

simply use two diff insert sql lines two complete your job.....
Post Reply