php - update immediately inserted rows without updating the older ones -


if inserted rows , want update 1 column value of rows inserted in process without update 1 column value of older rows inserted in previous process can see code , understand more clearly:

<?php  session_start(); ?>  <form action="" method="post" name="data_table"> <tbody > <?php  require_once("dbconfig.php"); error_reporting(0); $id=$_post['id']; $class=$_post['class']; $d = new datetime('now', new datetimezone('asia/baghdad')); $date=$d->format('y-m-d h:i:s'); $q="select * students class='$class'"; $qq=mysql_query($q)   or die(mysql_error());  echo "<table border='2'> <tr> <th>الأسم</th> <th>الحضور</th> </tr><tr>"; while($row=mysql_fetch_array($qq)){ ?> <input type="hidden" name="class" value="<?php echo $row['class']; ?>" > <td><input type="checkbox" value="<?php echo $row['id']; ?>" name="id[]" ></td> <td><b><?php echo $row['username']; ?></td> <tr>  <?php } ?> </table> <?php if (isset($_post['submit'])) {if(empty($id) || $id==0) { echo " please check "; } else { $impid=implode(", ",$id); $qdel=mysql_query("insert attendees select * `students` class='$class'"); $qdel=mysql_query("update attendees set datetime='$date'");  if (isset($qdel)){ echo "<h2> done </h2>";} } } ?> </tbody> </form> 

the problem update query updating value of datetime column in rows inserted , before question how can make update query work each inserting process separated previous 1 can please ? thanks

doing update right after insert inefficient. isn't idea rely on columns of 2 different tables match.

you can insert static string in query.

insert attendees (column1, column2, column3, datetime)  select column1, column2, column3, '$date' students class='$class' 

however, breaks normalization standards of rdbms. best way not duplicate data attendees, reference foreign key student id in attendees. shouldn't have update 2 tables updates student's information. suggest read on database normalization before designing database.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -