php sprintf() 是什么意思:参数太少
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31954813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the meaning of sprintf(): Too few arguments
提问by eniac05
I have an sql query like this
我有一个像这样的 sql 查询
if (isset($_POST['no_peserta_mhs_2015'])) {
$colname_rec_mhs_2015 = $_POST['no_peserta_mhs_2015'];
}
mysql_select_db($database_connect, $connect);
$query_rec_mhs_2015 = sprintf("SELECT * FROM mhs_2015 WHERE no_peserta_mhs_2015 = %s or nama_mhs_2015 like %s ", GetSQLValueString($colname_rec_mhs_2015, "text"));
But I get this error
但我收到这个错误
Warning: sprintf(): Too few arguments in C:\xampp\htdocs\gugus_2015\index.php on line 39 Query was empty
I don't know what's wrong.
我不知道怎么了。
回答by Paul Coldrey
You have two %s items in the string but only one parameter supplied after the string. For each '%' item in the format string it expects a matching parameter after the string to use to find in the value.
字符串中有两个 %s 项,但在字符串后只提供了一个参数。对于格式字符串中的每个 '%' 项目,它需要在字符串后面有一个匹配参数,用于在值中查找。
like this:
像这样:
sprintf("item 1: %s, item 2: %s", "item1", "item2");
what you have is like:
你拥有的是:
sprintf("item 1: %s, item 2: %s", "item1");
so there is no entry for the item 2 string to match
所以没有条目 2 字符串匹配