我知道这与这里的许多其他帖子相同,但我无法弄清楚!
我的代码如下所示:
$i=0;
$shelves = array();
$shelves['position'] = array();
$query = "select id, cat_id, book_title, writer, publisher, issue_year, copies, abstract from library where $table like '%$search_param%'";
$result = mysql_query($query);
while ( $data = mysql_fetch_assoc($result) ) {
error_log($data['id']);
$shelves['position'][$i]['id'] = $data['id'];
$shelves['position'][$i]['cat_id'] = $data['cat_id'];
$shelves['position'][$i]['book_title'] = $data['book_title'];
$shelves['position'][$i]['writer'] = $data['writer'];
$shelves['position'][$i]['publisher'] = $data['publisher'];
$shelves['position'][$i]['issue_year'] = $data['issue_year'];
$shelves['position'][$i]['copies'] = $data['copies'];
$shelves['position'][$i]['abstract'] = $data['abstract'];
++$i;
}
error_log( count($shelves['position']) );
而且因为有像这样的其他帖子的音调,我尝试了他们的解决方案:
$query = sprintf("select id, cat_id, book_title, writer, publisher, issue_year, copies, abstract from library where %s like'%%%s%'",mysql_real_escape_string($table),mysql_real_escape_string($search_param) );
或类似的东西:
$query = "select id, cat_id, book_title, writer, publisher, issue_year, copies, abstract from library where $table like '%{$search_param}%'";
我也尝试在没有动态变量的情况下运行查询,而我得到了同样的结果。
$query = "select id, cat_id, book_title, writer, publisher, issue_year, copies, abstract from library where book_title like '%lord%'";
似乎没有任何效果。
我已经在 mysql 工作台上测试了我的查询,它就像一个魅力!
在所有三个查询中,我从来没有得到第一个 error_log 的日志,而第二个每次都对我大喊 0!
有人可以照亮路吗?