更新列中具有不同表数据的记录

时间:2014-08-08 00:48:32

标签: php mysql

我遇到的问题是来自表(trans)的记录循环,在此循环中有一个来自表(用户)的用户下拉列表。

我想针对表(用户)中的每条记录更新表(trans)的驱动列。这里是代码

$records = mysql_query("SELECT * FROM trans WHERE (receiver = '".$receiver."' && cdate = '".$cdate."') ", $conn_str);
    $count = mysql_num_rows($records);
 }  

    elseif($count > "0"){echo  "<h3>" . $count . " - Records Found</h3>";}
      elseif($count < "0"){echo  "<h3 style='color:red'> NO Records Found</h3>";}

  if($records === FALSE) {die(mysql_error());}


if($count > 0){

while ($row = mysql_fetch_array($records)) {
  echo "<tr class='records'>" ;
  echo "<td>"  .  $counter++ . "</td>";
  echo "<td>"  .  $row ['cust_name'] . "</td>";
  echo "<td>"  .  $row ['house'] . "</td>";
  echo "<td>"  .  $row ['street'] . "</td>";
  echo "<td style='text-transform:uppercase'>"  .  $row ['post_code'] . "</td>";
  echo "<td>"  .  $row ['cust_cellno'] . "</td>";
  echo "<td>"  .  $row ['bags'] . "</td>";
  echo "<td>"  .  $row ['remarks'] . "</td>";
  echo "<td>"  .  $row ['ref_id'] . "</td>";
  echo "<td>"  .  $row ['receiver'] . "</td>";
  echo "<td>"  .  $row ['cdate'] . "</td>";
  echo "<td>"  .  $row ['collect_date'] . "</td>";
  echo "<td>"  .  $row ['type_of_call'] . "</td>";
  echo "<td>"  .  $row ['ctime'] . "</td>";
  ?>

<td>
<? $q = "SELECT username FROM ".DBTBLE." where user_level = '2' ";
    $drivers = mysql_query($q);
    $num_rows = mysql_numrows($drivers);    
     ?>

   <select name="Driver">
      <option>Select Driver</option>
      <? for($i=0; $i<$num_rows; $i++){
      $name=mysql_result($drivers,$i,"username");
      echo "<option value=\"$name\">$name</option>";}?>
    </select>       
  </td> 

上面的下拉列表基本上来自表(用户)。

<form method="post" name="update_form" action="<?php $_PHP_SELF ?>">
  <input name="trans_id" type="text" id="trans_id" value="<? echo $trans_id; ?>" />
  <input type="submit" name="update_btn" class="update" value="Update">
</form>
<?
   if(isset($_POST['update_btn'])) {

  $update = mysql_query("UPDATE trans SET driver='$name' WHERE trans_id='". $row["trans_id"] ."'", $conn_str);
$retval = $update;

if($retval){
 echo "<center><h2>Booking Successfully Updated</h2></center>"; 
 }
   else {die('Could not update data:' . mysql_error());
   }
  }
?>

两个表中都没有共同字段。

0 个答案:

没有答案