php pdo show tables,PHP PDO更新有2个表(PHP PDO Update with 2 tables)

PHP PDO更新有2个表(PHP PDO Update with 2 tables)

我有一点问题。 这就是我想要的:我有2个mysql表(类别,通道),通道表中有一个cat_id。 我想更新/编辑产品并将其放在另一个类别中,但即使产品的父ID(cat_id)为5,我创建的代码也只显示一个类别(id = 1)。

try {

//prepare query

$query = "select channel_id, name, category_id from channels where channel_id = ? limit 0,1";

$stmt = $pdo->prepare( $query );

//this is the first question mark

$stmt->bindParam(1, $_REQUEST['id']);

//execute our query

$stmt->execute();

//store retrieved row to a variable

$row = $stmt->fetch(PDO::FETCH_ASSOC);

//values to fill up our form

$channel_id = $row['channel_id'];

$name = $row['name'];

$category_id = $row['category_id'];

}catch(PDOException $exception){ //to handle error

echo "Error: " . $exception->getMessage();

}

$query2 = "SELECT * FROM categories";

$stmt2 = $pdo->prepare( $query2 );

$stmt2->execute();

$results = $stmt2->fetchAll(PDO::FETCH_ASSOC);

?>

Channel Name
Category

I have a little problem. This is what I want to achive: I have 2 mysql tables (categories, channels), the channel table has a cat_id in it. I want to update/edit a product and place it in another category but the code that I've made shows just one category (id=1) even if the product has a parent id(cat_id) of 5.

try {

//prepare query

$query = "select channel_id, name, category_id from channels where channel_id = ? limit 0,1";

$stmt = $pdo->prepare( $query );

//this is the first question mark

$stmt->bindParam(1, $_REQUEST['id']);

//execute our query

$stmt->execute();

//store retrieved row to a variable

$row = $stmt->fetch(PDO::FETCH_ASSOC);

//values to fill up our form

$channel_id = $row['channel_id'];

$name = $row['name'];

$category_id = $row['category_id'];

}catch(PDOException $exception){ //to handle error

echo "Error: " . $exception->getMessage();

}

$query2 = "SELECT * FROM categories";

$stmt2 = $pdo->prepare( $query2 );

$stmt2->execute();

$results = $stmt2->fetchAll(PDO::FETCH_ASSOC);

?>

Channel Name
Category

原文:https://stackoverflow.com/questions/19861467

更新时间:2020-01-05 06:59

最满意答案

代替

尝试:

Instead of

Try:

2013-11-08

相关问答

实际上, PDO::beginTransaction()遵循与MySQL中的START TRANSACTION语句相同的规则, 这里有更多信息。 这意味着MySQL不会立即锁定表,但会遵循ACID规则。 请注意,如果您需要显式锁定某些表,您可以执行以下操作: $db->beginTransaction();

$db->exec('LOCK TABLES t1, t2, ...');

Actually PDO::beginTransaction() follows the same rules a

...

代替 <?php foreach($results as $rows) {?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值