/    Sign up×
Community /Pin to ProfileBookmark

query problems

probley an easy one, but I can see the problem for looking. for some reason this code keeps looping and never stops displaying the same and only record over and over

[code]
$album_owner = ‘0000010’;

$get_album = (“SELECT album_name, album_cover, album_create_date, image_count, album_id FROM albums WHERE album_owner = ‘$album_owner'”);
$album = mysql_query($get_album )or die(“SQL Error: $get_album <br>” . mysql_error());

?>

<?php while($albums = mysql_fetch_assoc($album)){
$folder_name = $albums[‘album_name’].’-‘.$albums[‘album_id’];
$album_id = $albums[‘album_id’];

$album = mysql_query($get_album)or die(“SQL Error: $get_album_cover <br>” . mysql_error());

//Get Album Cover

$get_album_cover = (“SELECT album_id, photo_name FROM photos WHERE album_id = ‘$album_id'”);
$album_cover = mysql_query($get_album_cover)or die(“SQL Error: $get_album_cover <br>” . mysql_error());

$cover = mysql_fetch_assoc($album_cover);

?>
<div style=”width:210px; height:210px; float:left;”>
<img src=”gallery/<?php echo $folder_name; ?>/thumbs/th_<?php echo $cover[‘photo_name’]; ?>” width=”200″ height=”133″>
<dl class=”gallery”>
<dt class=”gallery”>Album Name:</dt> <dd><?php echo $albums[‘album_name’]; ?></dd>
<dt class=”gallery”>Photo Account:</dt> <dd>10</dd>
<dt class=”gallery”>Album Views:</dt> <dd>69</dd>

</dl>

</div>

<? } ?>
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@DistantUKMay 07.2009 — Try this:

[code=php]$album_owner = '0000010';

$get_album = ("SELECT album_name, album_cover, album_create_date, image_count, album_id FROM albums WHERE album_owner = '$album_owner'");
$album = mysql_query($get_album )or die("SQL Error: $get_album <br>" . mysql_error());

?>

<?php while($albums = mysql_fetch_assoc($album)){
$folder_name = $albums['album_name'].'-'.$albums['album_id'];
$album_id = $albums['album_id'];

$album = mysql_query($get_album)or die("SQL Error: $get_album_cover <br>" . mysql_error());

//Get Album Cover

$get_album_cover = ("SELECT album_id, photo_name FROM photos WHERE album_id = '$album_id'");
$album_cover = mysql_query($get_album_cover)or die("SQL Error: $get_album_cover <br>" . mysql_error());

$cover = mysql_fetch_assoc($album_cover);
$cover = $cover['photo_name'];
$albums = $albums['album_name'];

echo '
<div style="width:210px; height:210px; float:left;">
<img src="gallery/'.$folder_name.'/thumbs/th_'.$cover.'" width="200" height="133">
<dl class="gallery">
<dt class="gallery">Album Name:</dt> <dd>'.$albums.'</dd>
<dt class="gallery">Photo Account:</dt> <dd>10</dd>
<dt class="gallery">Album Views:</dt> <dd>69</dd>

</dl>

</div>
';

}
mysql_free_result()
?>[/code]


No guarantees, I have changed a few things... One thing i noticed was that the "While" argument:

[code=php]while($albums = mysql_fetch_assoc($album))[/code]

[COLOR="Red"]$albums[/COLOR] isn't given a value.
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...