更新具有相同标题但具有不同ID的所有列

时间:2017-04-02 12:38:12

标签: php

我有一个名为collection的表,并且包含title,author,edition,volume等列。现在,我希望能够更新所有使用相同标题编辑但具有不同ID的列。

这是我的示例代码

$con=mysqli_connect("localhost","root","","library03");
    $check="SELECT * FROM collection WHERE title = '$_POST[title]'";
    $rs = mysqli_query($con,$check);
    $data = mysqli_fetch_array($rs, MYSQLI_NUM);
    if($data[0] > 1) {
        for($i=0;$i<=COUNT($data);$i++){
        $sql="UPDATE collection SET author = '$new_author' WHERE title = '$_POST[title]'";
        $sql_connect = mysqli_query($sql);

这些都在我的$ _POST

之下
$collection = Collection::find_by_id($_POST['id']);
    $collection->date_received      = $_POST['date_received'];
    $collection->title              = $_POST['title'];
    $collection->author             = $_POST['author'];
    $collection->edition            = $_POST['edition'];
    $collection->volume             = $_POST['volume'];
    $collection->pages              = $_POST['pages'];
    $collection->cost               = $_POST['cost'];
    $collection->publisher          = $_POST['publisher'];
    $collection->pub_year           = $_POST['pub_year'];
    $collection->remarks            = $_POST['remarks'];
    $collection->call_number        = $_POST['call_number'];
    $collection->col_copy           = $_POST['col_copy'];

0 个答案:

没有答案