我有一個PHP腳本,根據從MySQL數組中選擇的行將行插入到表中。將公共ID分配給MySQL數組中的多行插入
的代碼行插入新表:
$sql="insert into loaddetails (CaseNo,GrossMass,CaseStatus,Customer)
select `case no`,`gross mass`,`case status`, customer from
availablestock where `case no` = '$val'";
我要指派所有插入的行相同的ID,以便多個stock
項目共享相同的LoadID。
我該如何修改我的代碼才能這樣做,以便所有插入的記錄都共享相同的ID,並且ID對於加載是唯一的。
我想我可以使用下面的代碼來獲取最大ID和一個
SELECT max(loadid)+1 from loaddetails
我怎樣才能達致這增加了嗎?我意識到我的PHP代碼是不完美的,但它是功能性的,我只需要添加的功能以允許行具有共同ID插入到產生如下結果:
謝謝提前協助。
問候, 萊恩史密斯
完整代碼:
<?php
mysql_connect("localhost", "user", "password")or die("cannot connect");
mysql_select_db("databasename")or die("cannot select DB");
$sql="SELECT `case no`,`customer`,`gross mass`, `case status` from availablestock where transporttypename= 'localpmb'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table border=1>
<tr>
<td>
<form name="form1" method="post">
<table>
<tr>
<td>#</td>
<td>Case Number</td>
<td>Customer</td>
<td>Weight</td>
<td>Status</td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><input type="checkbox" name=check[] value="<?php echo $rows['case no']; ?>"></td>
<td><?php echo $rows['case no']; ?></td>
<td><?php echo $rows['customer']; ?></td>
<td><?php echo $rows['gross mass']; ?></td>
<td><?php echo $rows['case status']; ?></td>
</tr>
<?php
}
?>
<tr>
<td><input name="planlocalpmb" type="submit" id="planlocalpmb" value="planlocalpmb"></td>
</tr>
<?php
$check=$_POST['check'];
if($_REQUEST['planlocalpmb']=='planlocalpmb'){
{
$sql="insert into loaddetails (CaseNo,GrossMass,CaseStatus,Customer) select `case no`,`gross mass`,`case status`, customer from availablestock where `case no` = '$val'";
foreach($check as $key=>$value)
{
$sql="insert into loaddetails (CaseNo,GrossMass,CaseStatus,Customer) select `case no`,`gross mass`,`case status`, customer from availablestock where `case no` = '$value'";
$final=mysql_query($sql);
if($final)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=php.php\">";
} }
}
}
// Check if delete button active, start this
// if successful redirect to php.php
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
做u想相同的負載分配id的所有行?或者什麼是具有相同加載ID的常見事物? – diEcho
嗨,對於數組中所有選定的行,當插入新表時應該有相同的loadid。 loadid是常用鏈接,因此一個loadid將在其上有多個案例。 loadid代表實際卡車和卡車上的貨物。謝謝 – Smudger