Php 使用变量sprintf和Join更新表
我试图通过一个连接查询使用sprintf设置一个变量,然后每次这个变量出现在表中时使用加载到查询中的ID进行更新 如果我使用一个稍有不同的查询,但却给出了一组相同的结果,那么更新就可以正常工作,所以我得出结论,我在做一些愚蠢的事情 以下是一个选择:Php 使用变量sprintf和Join更新表,php,mysql,variables,join,printf,Php,Mysql,Variables,Join,Printf,我试图通过一个连接查询使用sprintf设置一个变量,然后每次这个变量出现在表中时使用加载到查询中的ID进行更新 如果我使用一个稍有不同的查询,但却给出了一组相同的结果,那么更新就可以正常工作,所以我得出结论,我在做一些愚蠢的事情 以下是一个选择: //below is a simpler version of what I would like to work with the update $sql=sprintf("SELECT `test`.`id` FROM `test` JOIN
//below is a simpler version of what I would like to work with the update
$sql=sprintf("SELECT `test`.`id` FROM `test` JOIN `test2` ON (test.agent=test2.user) WHERE `test`.`type`='new' AND `test2`.`note` = 'p';
//this is what works, even though the output (list of test.id) is identical to above
$sql=sprintf("SELECT `id` FROM `test` WHERE `test`.`type`='new' AND `agent`='test.user';
//here is my update that works with the second select
if($ref_id = mysql_one_data($sql)){
$updateSQL= sprintf("UPDATE `test` SET `type`='testdata', `priority`=%s, `note`=%s WHERE `id`=%s;",SQLVal('100', "int"),SQLVal($note, "text"),SQLVal($ref_id, "int"));
$result = mysql_query($updateSQL) or die(mysql_error());
$processed=TRUE; $result="updated";
$count_converted++;
}
有什么想法吗?我完全不知所措!正如我所说的,两个查询都给出100%相同的输出,所以生成的变量应该是相同的,对吗?因此,如果一个更新在找到相应的值时起作用,那么另一个也应该起作用。在前两个sprintf中缺少一个结束引号和括号。问题中的拼写错误或“真正的”问题?“问题”。。。询问打字错误时的典型情况;-)错别字,就是在这里我简化了它,并删除了另一个变量,该变量在末尾设置为文本。最后应该是-“,SQLVal($ticket_id,“text”);解决了这个问题,我没有复制我在select中漏掉“.”的地方。在PHP MyAdmin和MYSQL workbench中运行查询时,这很好,但在PHP中它没有任何内容