I'm trying to select values from my database when the value != 0 but all I get is an empty array.
Here I've got an array with all the names who are also in the database.
$array = ['helm' , 'weapon', 'amulet', 'body', 'legs', "boots", 'shield', 'gloves', 'cape'];
then I place the array in a foreach loop and place the _name
and _value
behind the name (in the database it is helm_name = blabla
_helm value = 10
)
When the text is placed behind the word I loop through it in my query
in which I try to select the name table (for example helm_name
) and the value table (for example helm_value)
foreach($array as $array_item){
$array_item_name = $array_item.'_name';
$array_item_value = $array_item.'_value';
$sql = $db->prepare("SELECT ".$array_item_name." FROM player WHERE naam = :naam AND ".$array_item_value." != 0");
$sql->execute(array(":naam" => $naam));
$fetch = $sql->fetchAll(PDO::FETCH_ASSOC);
}
but all it returns when I run it is Array ( )
what am I doing wrong?
请检查数据库错误值,也应首先创建sql字符串并输出它,以便可以手动运行生成的sql语句。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.