如果album = 1,这可以很好地工作,但之后拒绝完成查询。
function findThumbnail($album, $photo) {
echo 'Variable Check : Album ='.$album.' & PHOTO = '.$photo; // this always works
$thumbQuery = "SELECT albums.*, photos.*
FROM photos
INNER JOIN albums
ON photos.album_id = albums.album_id
WHERE photos.album_id = $album AND photos.photo_id = $photo
";
$thumbResult = mysql_query($thumbQuery);
while($thumbData = mysql_fetch_array($thumbResult))
{
$photo_filename = $thumbData['photo_filename'];
$album_directory = $thumbData['album_directory'];
}
$thumbAddress = 'photos/'.$album_directory.'/thumbs/'.$photo_filename.'.jpg';
return $thumbAddress;
}
我看不到它。任何人吗?
更新
(谢谢大家对新人的好感)
我不确定如何更具体地使用查询(为$ album添加1以外的任何数字会导致失败),但错误如下:
Notice: Undefined variable: album_directory in functions.php on line 80
第80行
$thumbAddress = 'photos/'.$album_directory.'/thumbs/'.$photo_filename.'.jpg';
相关表格如下
+----------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------+------+-----+---------+----------------+
| photo_id | int(11) | NO | PRI | NULL | auto_increment |
| photo_filename | text | YES | | NULL | |
| album_id | int(10) | YES | | NULL | |
| photo_caption | text | YES | | NULL | |
+----------------+---------+------+-----+---------+----------------+
+----------------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+---------+------+-----+---------+----------------+
| album_id | int(11) | NO | PRI | NULL | auto_increment |
| album_year | int(2) | YES | | NULL | |
| album_month | int(2) | YES | | NULL | |
| album_day | int(2) | YES | | NULL | |
| album_status | int(2) | YES | | NULL | |
| album_caption | text | YES | | NULL | |
| album_location | text | YES | | NULL | |
| album_title | text | YES | | NULL | |
| album_directory | text | YES | | NULL | |
| album_cover_filename | text | YES | | NULL | |
+----------------------+---------+------+-----+---------+----------------+
要回答“多少”问题,它应该返回一个。我不熟悉货物崇拜编程一词,但此刻我对此并不熟悉。
感谢您的时间评论!
答案 0 :(得分:1)
如果您的查询没有返回任何记录,因为您没有在while循环之外定义$album_directory
,因此不会设置它,并且您会收到Notice: Undefined variable: album_directory in functions.php on line 80
通知。< / p>
如果您的查询只返回一个结果,请考虑在查询末尾添加LIMIT 1
。除此之外,当您只期望单行时,不要启动while循环,而是使用mysql_num_rows($thumbResult);
中的结果来确定返回的实际行数,然后使用mysql_fetch_array($thumbResult);
来获取数据
答案 1 :(得分:0)
所以基本上,通知告诉你你的innerhalb while循环从未执行过。这是因为faild查询或空结果