如何将字符串与声明的变量连接起来?
block_id
列是外键,
我想插入room_id = Block 2/R1
和block_id = Block 2
。
require 'db.php';
$block = 2;
for($i=1;$i <= 50; $i++){
$sql = $mysqli->query("INSERT INTO `room` (`room_id`, `room_type`, `blck_id`) "
. "VALUES ('Block '.$block.'/R'.$i, 'Double', 'Block '.$block)");
答案 0 :(得分:1)
您不需要在查询字符串中添加.
。
$mysqli->query("INSERT INTO `room` (`room_id`, `room_type`, `blck_id`) "
. "VALUES ('Block $block/R$i', 'Double', 'Block $block')");
如果要查询$block = 1
和$i = 2
INSERT INTO `room` (`room_id`, `room_type`, `blck_id`) VALUES ('Block 1/R2', 'Double', 'Block 1')