Php 在另一个函数中使用数组中的键所持有的值来查询数据库
我有一个在数据库中搜索表的函数,它工作得很好。现在,我有了一个新函数,用于在第一个函数中拾取数组所持有的键的值,并查询数据库中的另一个表。它似乎不起作用 这是我的密码:Php 在另一个函数中使用数组中的键所持有的值来查询数据库,php,mysql,Php,Mysql,我有一个在数据库中搜索表的函数,它工作得很好。现在,我有了一个新函数,用于在第一个函数中拾取数组所持有的键的值,并查询数据库中的另一个表。它似乎不起作用 这是我的密码: public function getTransformers() { $deb = array(); //I made this global at the top of the class $trans = mysql_query('SELECT * FROM transformers'); whi
public function getTransformers() {
$deb = array(); //I made this global at the top of the class
$trans = mysql_query('SELECT * FROM transformers');
while($row = mysql_fetch_array($trans)) {
$den[$row['codes']]["name"] = $row["name"];
$den[$row['codes']]["codes"] = $row["codes"];
$den[$row['codes']]["previous_reading"] = $row["previous_reading"];
$den[$row['codes']]["current_reading"] = $row["current_reading"];
array_push($this->deb, $den);
}
$this->getBookcodes($this->deb);
}
public function getBookcodes($transformers) {
$trans =mysql_query("SELECT book_code FROM transformer_book_codes WHERE transformer_codes = '$key'");
$books = [];
foreach ($transformers as $item) {
echo $this->getTransformers('name')["codes"];
}
}
你有这样的想法吗
public function getBookcodes($transformers) {
$books = [];
foreach ($transformers as $key => $value) {
$trans =mysql_query("SELECT book_code FROM transformer_book_codes WHERE transformer_codes = '".$key. "'");
while($row = mysql_fetch_assoc($trans)) {
$books[] = $row;
}
}
}
你能告诉我什么“似乎不起作用”吗?它不会返回“transformer\u book\u codes”表上的值。因为我打算使用transformer表中的“code”返回存储在该表某列中的值,所以在询问问题(此处或离线)时切勿使用“not working”(不工作),请始终描述确切的错误。永远不要使用mysql_*函数。阅读sql连接