SQL leaving one result out

Discussion forum for MOD Writers regarding MOD Development.
Locked
Jhonne
Registered User
Posts: 21
Joined: Sat Feb 27, 2010 7:36 pm

SQL leaving one result out

Post by Jhonne » Sat Oct 29, 2011 12:11 pm

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,
	
	));

User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 50557
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: SQL leaving one result out

Post by stevemaury » Sat Oct 29, 2011 12:48 pm

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.
For REALLY good and VERY inexpensive hosting CLICK HERE

I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51758
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: SQL leaving one result out

Post by Brf » Sat Oct 29, 2011 1:09 pm

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.

Jhonne
Registered User
Posts: 21
Joined: Sat Feb 27, 2010 7:36 pm

Re: SQL leaving one result out

Post by Jhonne » Sat Oct 29, 2011 1:15 pm

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 :)

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51758
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: SQL leaving one result out

Post by Brf » Sat Oct 29, 2011 1:17 pm

In the future, post here in Mod Writers Discussion, not Support.

Locked

Return to “[3.0.x] MOD Writers Discussion”