[英]How to check database with an array parameter?
Hi, I have an array and I want to pass a variable to a function. 嗨,我有一个数组,我想将变量传递给函数。
'#\@(.*?)\;#si' => 'some before text' . retrieveName('$1') . 'some after text,'
function retrieveName($poster_id){
$sanitized_id = sanitizeIn($poster_id);
$getname = mysql_query("SELECT * FROM users WHERE userid = '$sanitized_id';")
or die(mysql_error());
$namerow = mysql_fetch_array($getname);
$exists = mysql_num_rows($getname);
if($exists == "0"){
return $sanitized_id;
} else {
return $namerow['username'];
}
}
It's supposed to take the value of $1
, check the database for a user with that id, then return their username. 应该采用$1
的值,检查数据库中具有该ID的用户,然后返回其用户名。 But no parameter is being passed to retrieveName 但是没有参数传递给retrieveName
The retrieveName function should read: resolveName函数应显示为:
function retrieveName($poster_id){
$sanitized_id = sanitizeIn($poster_id);
$get_name = mysql_query("SELECT * FROM users WHERE userid = '$sanitized_id';") or die(mysql_error());
$name_row = mysql_fetch_array($get_name);
return $name_row['username'];
}
I strongly advise on placing some error checking there though, what happens if the ID is not found? 我强烈建议您在此处进行一些错误检查,如果没有找到ID怎么办?
Edit: 编辑:
if you're trying to do a "preg_replace templating", then the line should read: 如果您要进行“ preg_replace模板制作”,则该行应显示为:
'#@(.*?);#sie' => '"some before text".retrieveName("\1")."some after text"',
'e' in the modifiers to execute the code. 修饰符中的“ e”以执行代码。
This should change, eg, "Hello, @lserni;, how goes?" 这应该更改,例如,“你好,@ lserni ;,怎么回事?” with "Hello, some before textLeonardo Sernisome after text, how goes?". 与“您好,一些在文本之前,莱昂纳多·瑟尼索姆在文本之后,怎么样?”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.