0
 $cteachers = mysql_query("SELECT * FROM teachers WHERE teachers.stats = '1'") or die(mysql_error());
while($info = mysql_fetch_array( $cteachers ))
{

Print "<li><strong>$info['id'];</strong></li><li><strong>$info['name'];</strong></li>"<li><strong>$info['rnk'];</strong></li>;

$id = $info['id'];
$cnme = $info['name'];
$fnme = $info['f_name'];
$lnme = $info['l_name'];
$rnkk = $info['rnk'];

  $fullname = $fnme." ".$lnme;


if ($cnme == '')
{
$que2 = "UPDATE teachers (name) VALUES('$fullname') WHERE teachers.f_name = '"$fnme"' AND teachers.l_name = '"$lnme"'" or die(mysql_error());
$exe2 = mysql_query($que2) or die(mysql_error());

}

您好,我遇到了一个问题,请帮助我,它将提供教师的完整列表,但如果教师全名字段为空,则更新它

4

3 回答 3

3

为什么不在一条 SQL 中完成呢?

UPDATE teachers
SET name = CONCAT(f_name, " ", l_name)
WHERE stats = "1"
AND name = ""

(如果它是一个可为空的字段,则将name = ""更改为name IS NULL )

于 2013-07-05T23:48:33.343 回答
0

你表的主键是什么?据我所知,我们可以根据主键更新表

或者

if (!isset($cnme)){
  $que2 = "UPDATE teachers set name='$fullname' WHERE teachers.f_name = '"$fnme"' AND teachers.l_name = '"$lnme"'";
  $exe2 = mysql_query($que2) or die(mysql_error());

}
于 2013-07-05T23:50:22.737 回答
0

您应该使用 mysqli 而不是 mysql 或 PDO 类来利用准备好的语句

if(empty($fnme) && empty($lnme)){
    $que2 = "UPDATE teachers set name='$fullname' WHERE id='$id'";
    $exe2 = mysqli_query($link,$que2);//$link is the conncetion parameter
}
于 2013-07-05T23:52:50.267 回答