Page 1 of 1

SQL leaving one result out

Posted: Sat Oct 29, 2011 12:11 pm
by Jhonne
I'm using the phpbb gallery mod and trying to make it so that the user albums is shown on the profile page for each user. My problem is that one album is left out from the array and it is like this on every profile.

This is the code I got, anyone can see why this is happening?

Thanks for any help,
Jhonne

Code: Select all

	$sql = 'SELECT *
		FROM ' . GALLERY_ALBUMS_TABLE . '
		WHERE album_user_id = ' . $user_id;
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
	while ($row = $db->sql_fetchrow($result)) {
		$show_albums 	.= $row['album_name'] . ', ';
		$albums 		.= append_sid("{$phpbb_root_path}{$gallery_root_path}album.$phpEx", 'album_id=' . $row['album_id']) . '<br />';	
	}
	$db->sql_freeresult($result);
	
	$template->assign_vars(array(
		'USER_ALBUMS'	=> $show_albums,
		'ALBUMS'		=> $albums,
	
	));

Re: SQL leaving one result out

Posted: Sat Oct 29, 2011 12:48 pm
by stevemaury
To receive MOD support please visit our Customisations Database and post in the specific MOD's designated support area. The link to the support area for each released MOD is also available in the first post of each released MOD listed in the MOD Database Releases forum.

Re: SQL leaving one result out

Posted: Sat Oct 29, 2011 1:09 pm
by Brf
Your answer is pretty easy:

Code: Select all

 $row = $db->sql_fetchrow($result);
   while ($row = $db->sql_fetchrow($result)) {
That first statement is getting the first row, and the second one starts with the second row, and you have not stored off the first one...
Just omit the first line.

Re: SQL leaving one result out

Posted: Sat Oct 29, 2011 1:15 pm
by Jhonne
Thanks, it works now :)

I posted it here cause I thought it was more of a general SQL or php question rather than a question related to the mod. But I will think about that the next time I post :)

Re: SQL leaving one result out

Posted: Sat Oct 29, 2011 1:17 pm
by Brf
In the future, post here in Mod Writers Discussion, not Support.