以下函数提供除artist_id之外的所有相关数据,运行时我已经检查了数据库中的所有元素并且确定。
如果我将artist_id更改为实际的'id',它会在函数的结果中显示为WHERE artist_id = 4 AND ........
承认我不明白造成这种情况的原因。功能结果:
SELECT `image_album_id`, `member_id`, `artist_id`, `albumname`, `ext`, `timestamp`
FROM album_images WHERE artist_id = AND member_id = 1 AND
image_album_id = 160
<?php
function get_data_nxtprv($fields, $where) {
$return = FALSE;
// Template
$template = "SELECT %s "
. "FROM album_images "
. "WHERE artist_id = " . $artist_id. "
AND member_id = ".$_SESSION['member_id']." %s";
// Current record
$sql = sprintf($template, $fields, $where);
$query = mysql_query($sql);
$query_result = mysql_fetch_assoc($query);
//print_r($sql);
// If data has been found
if ($query_result)
{
$return = $query_result;
}
return $return;
?>
答案 0 :(得分:0)
我不完全确定我理解你的问题。但我注意到你的函数使用了三个输入变量:
$artist_id, $fields, $where
但$ artist_id并没有作为论据传递。
您需要修改函数调用:
function get_data_nxtprv($artist_id, $fields, $where)
答案 1 :(得分:0)
您的SQL中有错误
SELECT `image_album_id`, `member_id`, `artist_id`, `albumname`, `ext`, `timestamp`
FROM album_images WHERE artist_id = AND member_id = 1 AND
image_album_id = 160
不应该
SELECT `image_album_id`, `member_id`, `artist_id`, `albumname`, `ext`, `timestamp`
FROM album_images WHERE member_id = 1 AND
image_album_id = 160
如果artist_id
是您正在寻找的字段之一?