Я пытаюсь объединить несколько изображений в альбом и отобразить их на странице, используя foreach.
+----+----------+----------------------------------+-----------+----------+
| id | album_id | name | url | theme_id |
+----+----------+----------------------------------+-----------+----------+
| 1 | 1 | 60b0603f40993bfe86d54756505416cb | project_1 | 1 |
| 2 | 1 | 5efd6e08fed71ac6ad18bdde997e97bd | project_1 | 1 |
| 3 | 2 | fe4ac6806722e7cd74a60476da9ec4ea | project_2 | 1 |
| 4 | 2 | 87028bcd233b5ca5133fd0be335ff4b7 | project_2 | 1 |
| 5 | 2 | 9326d956c5cd30a75ff8b90d59e18273 | project_2 | 1 |
| 6 | 3 | 325925af3c04d936aa0e292b007b19e9 | project_3 | 1 |
| 7 | 3 | 0e087fb5e2038a746398d8dbe362032d | project_3 | 1 |
| 8 | 3 | 8be793e3e619771bb81e55c805d23b7d | project_3 | 1 |
+----+----------+----------------------------------+-----------+----------+
Когда я запускаю следующий код, я получаю правильное имя и URL для изображений в первом альбомном идентификаторе,но, например, в album_id = 2 я все равно получу URL проекта_1, а в album_id = 3 я получу URL проекта_2.Я полностью потерян.
$album = find_album($_GET['id']);
$albums = find_albums_by_theme($album['theme_id']);
$image = find_image($_GET['id']);
$images = find_images_by_album($image['album_id']);
$themes = find_themes();
<ul>
<?php foreach($images as $image): ?>
<li><img src="photos/<?php echo $image['url']; ?>/large/<?php echo $image['name']; ?>.jpg" alt="<?php echo safe_output($album['title']); ?>" /></li>
<?php endforeach; ?>
</ul>
И мои функции:
function find_image($id)
{
db_connect();
$query = sprintf("SELECT
images.id,
images.album_id,
images.name,
images.url,
albums.id
FROM
images, albums
WHERE
images.album_id = albums.id and
images.id = '%s'
",
mysql_real_escape_string($id));
$result = mysql_query($query);
if(!$result)
{
return false;
}
$row = mysql_fetch_array($result);
return $row;
function find_images_by_album($album_id)
{
db_connect();
$query = sprintf("SELECT images.id,
images.name,
images.url,
images.album_id,
albums.id,
albums.theme_id,
themes.name as theme,
themes.id
FROM
images, themes, albums
WHERE
images.album_id = albums.id and albums.theme_id = themes.id and
albums.id = '%d'
ORDER BY images.id;
",
mysql_real_escape_string($album_id));
$result = mysql_query($query);
if(!$result)
{
return false;
}
$result = db_result_to_array($result);
return $result;
}
function find_albums_by_theme($theme_id)
{
db_connect();
$query = sprintf("SELECT albums.id,
albums.title,
albums.theme_id,
albums.created_at,
albums.fullname,
albums.vote_cache,
themes.name as theme
FROM
albums, themes
WHERE
themes.id = '%s' and albums.theme_id = themes.id
ORDER by vote_cache DESC
",
mysql_real_escape_string($theme_id));
$result = mysql_query($query);
if(!$result)
{
return false;
}
$result = db_result_to_array($result);
return $result;
}
function find_themes()
{
db_connect();
$query = "SELECT * from themes order by id DESC";
$result = mysql_query($query);
if(!$result)
{
return false;
}
$result = db_result_to_array($result);
return $result;
}
function find_theme($id)
{
db_connect();
$query = sprintf("SELECT * FROM themes
WHERE id = '%s'
",
mysql_real_escape_string($id));
$result = mysql_query($query);
if(!$result)
{
return false;
}
$row = mysql_fetch_array($result);
return $row;
}
function find_album($id)
{
db_connect();
$query = sprintf("SELECT
albums.id,
albums.title,
albums.theme_id,
albums.created_at,
albums.fullname,
albums.vote_cache,
albums.discuss_url,
albums.description,
themes.name as theme
FROM
albums, themes
WHERE
albums.theme_id = themes.id and
albums.id = '%s'
",
mysql_real_escape_string($id));
$result = mysql_query($query);
if(!$result)
{
return false;
}
$row = mysql_fetch_array($result);
return $row;
}