【发布时间】:2011-01-04 08:15:09
【问题描述】:
如果某些字段包含数据,您将如何将多行插入数据库?考虑以下几点:
register_case = mysql_query ("INSERT INTO cases VALUES
('$case','$p_firstname','$p_lastname','$city'),
('$case','$p2_firstname','$p2_lastname','$city'),
('$case','$p3_firstname','$p3_lastname','$city')"
);
这会创建多个具有不同名字和姓氏的行,但大小写和城市保持不变。但是,如果只有 1 个条目,则仍会为其他 2 个条目创建一行。如何仅在给定字段中存在数据时才创建行?
【问题讨论】:
-
使用条件运算符动态构建此查询?