我有一個顯示mysql查詢結果的PHP頁面。每個返回的記錄都會分配一個複選框,其值等於行ID列。PHP Mysql聲明 - 多個語句
mysql語句原地插入選定的行到一個新的表。
我想添加第二個mysql查詢,更新所選ID匹配的另一個表的狀態。查詢低於:
UPDATE despgoods_alldetails,loaddetails SET despgoods_alldetails.locstatus = 'LoadCreated' WHERE despgoods_alldetails.despgoodsid = $ VAL
的作品是目前網頁PHP代碼(我知道一些不正確的代碼):
> <?php
> mysql_connect("localhost", "hulamin_hulamin", "Hulamin2011")or die("cannot connect");
> mysql_select_db("hulamin_loc")or die("cannot select DB");
> $sql="SELECT `despgoodsid`,`crtd dept`,`customer`,`loc cust rel`,`case no`,`gross mass`,`case width`,`case length` from
> despgoods_alldetails where transporttypename= 'localpmb' and
> locstatus='unplanned' and customer <> 'customer'";
> $result=mysql_query($sql);
> $count=mysql_num_rows($result); putenv("TZ=Africa/Johannesburg"); ?> <table border=0>
> <tr>
> <td>
> <form name="form1" method="post">
> <table border=0
> <tr>
> <th> </th>
> <th width=150>Dispatch Area</th>
> <th width=150>Customer</th>
> <th width=150><center>Release Number</th>
> <th width=130><center>Case Number</th>
> <th width=80><center>Weight</th>
> <th width=80><center>Width</th>
> <th width=80><center>Length</th>
> </tr> <?php
> while($rows=mysql_fetch_array($result)){ ?>
> <tr>
> <td><input type="checkbox" name=check[] value="<?php echo $rows['despgoodsid']; ?>"></td>
> <td><?php echo $rows['crtd dept']; ?></td>
> <td><?php echo $rows['customer']; ?></td>
> <td><center><?php echo $rows['loc cust rel']; ?></td>
> <td><center><?php echo $rows['case no']; ?></td>
> <td><center><?php echo $rows['gross mass']; ?></td>
> <td><center><?php echo $rows['case width']; ?></td>
> <td><center><?php echo $rows['case length']; ?></td>
>
> </tr>
>
> <?php
> } ?>
> <tr>
> <td colspan=3><input name="Next" type="submit" id="Next" value="Next"></td>
> </tr>
> <?php
>
>
>
> $check=$_POST['check'];
>
> if($_REQUEST['Next']=='Next'){ {
> $sql="INSERT INTO loaddetails (despgoodsid,dispatcharea,Customer, casenumber, weight, loadstatus)
> SELECT `despgoodsid`,`crtd dept`,Customer,`case no`,`gross mass`,'loadplanned'
> FROM despgoods_alldetails WHERE `despgoodsid` = '$val'";
>
> foreach($check as $key=>$value)
> {
> $sql="INSERT INTO loaddetails (despgoodsid,dispatcharea,Customer, casenumber, weight, loadstatus)
> SELECT `despgoodsid`,`crtd dept`,Customer,`case no`,`gross mass`,'loadplanned'
> FROM despgoods_alldetails WHERE `despgoodsid` = '$value'";
> $final=mysql_query($sql);
> if($final)
> {
> echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.hulaminloc.co.za/planningplatform/planlocalpmbstep2.php\">";
> } }
> }
> }
> mysql_close(); ?> </table> </form> </td> </tr> </table>
我怎樣才能添加我的更新語句運行除了選擇語句每個選定的行?
任何幫助表示讚賞。
感謝和問候, 萊恩史密斯
嗨,上面引用的PHP頁面將數據插入loaddetails表。然後我需要改變插入行的產品表的狀態。我不確定觸發器是否會對我所選的行進行調整。感謝@mishu – Smudger
考慮到需要更新的表是必須更新觸發器的查詢的一部分,在這裏不是這種情況;所以我認爲你不能避免使用兩個單獨的SQL查詢;只需運行插入後已有的更新查詢 – mishu
注意:它看起來像代碼將在系列中的第一次插入後重定向 – mishu