如何在mysql中更新2个表?

时间:2016-01-24 06:30:38

标签: mysql

我想更新两个名为:routing和routing_has_work_center

的表

在路由表中,用户可以在routing_has_work_center表中编辑描述,用户可以编辑production_hour。

<?php
session_start();
// include a php file that contains the common database connection codes
include ("dbFunctions.php");

//retrieve computer details from the textarea on the previous page
$description = $_POST['description'];
$production_hour=$_POST['$production_hour'];

//retrieve id from the hidden form field of the previous page
$theID = $_POST['routing_id'];

$msg = "";

//build a query to update the table
//update the record with the details from the form
$queryUpdate = "UPDATE routing SET description='$description' WHERE     routing_id = $theID";


//execute the query
$resultUpdate = mysqli_query($link, $queryUpdate) or die(mysqli_error($link));

//if statement to check whether the update is successful
//store the success or error message into variable $msg
if ($resultUpdate) {
$msg = "Record updated successfully!";
} else {
$msg = "Record not updated!";
}
?>

我有上面的代码但是当我更新生产时间时,它仍然是相同的,并且没有在routing_has_work_center数据库中更新。

我是否必须在查询中添加其他内容?

2 个答案:

答案 0 :(得分:0)

如果要更新2个表,则需要两个UPDATE语句。 你有一个。你错过了routing_has_work_center的那个。

尝试这样的事情:

$update_routing_center = 'UPDATE routing_has_work_center SET production_hour = $production_hour WHERE routing_id = $theID"`

通过mysqli_prepare($link, $update_routing_center);发表此声明之后 然后,您可以将该语句运行到数据库中。


修改:修改它以适应Ed Heal的评论

答案 1 :(得分:0)

检查一下。

func getRecom(completion: (result:String)->()) {

    let array = defaults.arrayForKey("recomQuery")
    print(array![0])

    for (index, object) in enumerate(array) {

        let videoURL = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails%2C+snippet&id=\(object)&maxResults=10&key=\(apiKey)"

        Alamofire.request(.GET, videoURL).validate().responseJSON { response in
            switch response.result {

            case .Success:
                if let value = response.result.value {
                    let json = JSON(value)
                    let videoTitle = json["items"][index]["snippet"]["title"].stringValue
                    let thumbPath = String(json["items"][index]["snippet"]["thumbnails"]["default"]["url"])
                    print(videoTitle)
                    print(thumbPath)
                    print(index)
                    let image = UIImage(data: NSData(contentsOfURL: NSURL(string: thumbPath)!)!)!
                    let newImage: NSData = UIImagePNGRepresentation(image)!
                    self.recomTitles.append(videoTitle)
                    self.recomThumbs.append(newImage)
                    defaults.setBool(true, forKey: "gotRecom")
                    completion(result: "done")
                }
            case .Failure(let error):
                print(error)
                completion(result: "done")
            }
        }
    }

    defaults.setObject(recomThumbs, forKey: "recomThumbs")
    defaults.setObject(recomTitles, forKey: "recomTitles")
}

recomendedQuery { (result:String) -> () in //Call functions
//CHANGE TO ONLY IF SUCCESS
Networking().getRecom() { (result:String) -> () in
self.recomView.reloadData()
}
}