首先,这是我的代码
$qry="SELECT * FROM Members WHERE member_id = '".$_SESSION['SESS_MEMBER_ID']."'";
$result=mysql_query($qry);
$check = mysql_fetch_assoc($result);
if($check['fullname'] == 0) {
$qry1 = "SELECT CONCAT( fname, ' ', lname ) AS firstlast FROM Members WHERE member_id = '".$_SESSION['SESS_MEMBER_ID']."'";
$result1 = mysql_query($qry1);
$qry2 = "UPDATE Members SET fullname = '$result1'"; }
我正在尝试执行以下操作: -
答案 0 :(得分:5)
在不知道问题的情况下,您可以在一个查询中完成所有这些操作:
UPDATE Members SET fullname=CONCAT(fname,' ',lname)
WHERE fullname=0 AND member_id = '".$_SESSION['SESS_MEMBER_ID']."'
答案 1 :(得分:2)
您可以通过一个查询轻松实现此目的:
UPDATE `Members`
SET `fullname` = CONCAT(`fname`, ' ', `lname`)
WHERE `member_id` = '".$_SESSION['SESS_MEMBER_ID']."'
AND `fullname` = 0
LIMIT 1;
答案 2 :(得分:1)
只能使用一个查询来执行此操作。
$query = "UPDATE Members SET fullname = CONCAT( fname, ' ', lname )
WHERE member_id = {$_SESSION['SESS_MEMBER_ID']}
AND fullname = 0"
答案 3 :(得分:0)
尝试:
$qry1 = "UPDATE Members SET fullname = CONCAT( fname, ' ', lname ) WHERE member_id = '".$_SESSION['SESS_MEMBER_ID']."'";
答案 4 :(得分:0)
您实际上只能在一个查询中执行此操作(不调用select一次)
UPDATE Members a
SET a.fullName = IF(fullname = 0, CONCAT(fname, ' ',lname), fullName)
WHERE member_ID = 'memberIDHERE'