PHP SQL SELECT然后UPDATE值

时间:2014-08-31 22:26:43

标签: php sql datetime-format

我有一个问题。

$db = JFactory::getDBO();

$res2 = $_data['DateSubmitted'];
//res2 returns 2014-08-31 12:03:02
$res3 = $_data['UserIp'];
//res3 returns 109.173.20.143 for example

$resdate = date('Y-m-d H:i:s', strtotime($res2));

$SubmId = $db->query("SELECT `SubmissionId` FROM `rrr_submissions` WHERE `FormId` = '20' AND `DateSubmitted`='".$resdate."' AND `UserIp`='".$res3."'");

$db->setQuery("UPDATE `rrr_submission_values` SET `FieldValue` = '".$SubmId."' WHERE `FieldName`='7_Status' AND `SubmissionId`='5682'");

$db->query();

在rrr_submissions中:

  • SubmissionId是INT(11)AUTO_INCREMENT
  • FormId是INT(11)
  • DateSubmitted是日期时间
  • UserIp是varchar(15)

在rrr_submission_values中:

  • FieldValue是文字
  • FieldName是文字
  • SubmissionId是int(11)

我做错了什么?结果我看到" 1"在FieldValue。

1 个答案:

答案 0 :(得分:1)

尝试加载结果行,然后调用字段值。

$db = JFactory::getDBO();

$res2 = $_data['DateSubmitted'];
//res2 returns 2014-08-31 12:03:02
$res3 = $_data['UserIp'];
//res3 returns 109.173.20.143 for example

$resdate = date('Y-m-d H:i:s', strtotime($_data['DateSubmitted']));

$SubmId = $db->query("SELECT `SubmissionId` FROM `rrr_submissions` WHERE `FormId` = '20' AND `DateSubmitted`='".$resdate."' AND `UserIp`='".$res3."'");

$row = $db->loadRow();

$SubmId = $row['SubmissionId'];

$db->setQuery("UPDATE `rrr_submission_values` SET `FieldValue` = '".$SubmId."' WHERE `FieldName`='7_Status' AND `SubmissionId`='5682'");

$db->query();