vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Break after X amount of images (https://vborg.vbsupport.ru/showthread.php?t=119576)

Kirk Y 06-24-2006 11:36 PM

Break after X amount of images
 
I've got a page displaying the members' profile pictures. The problem is that all the pictures are being placed on one line, so I'm trying to figure out how to add a <tr> after 5 images have been displayed. I've seen a few gallery hacks do this, but I only partially understand the process. This is what I've got so far:

PHP Code:

$users $db->query_read("
  SELECT *
  FROM user
 "
);
$userstotal $db->query_read("
  SELECT username
  FROM user
 "
);
$user_count mysql_num_rows($userstotal);
while (
$userinfo $db->fetch_array($users))
 {
   if (
$vbulletin->options['usefileavatar'])
   {
    
$userinfo['profilepicurl'] = $vbulletin->options['profilepicurl'] . '/profilepic' $userinfo['userid'] . '_' $userinfo['profilepicrevision'] . '.gif';
   }
   else
   {
    
$userinfo['profilepicurl'] = 'image.php?' $vbulletin->session->vars['sessionurl'] . 'u=' $userinfo['userid'] . "&amp;dateline=$userinfo[profilepicdateline]&amp;type=profile";
   }
   
$username $userinfo['username'];
   
$userid $userinfo['userid'];
   
$userinfopic .= "<td class=\"alt2\" height=\"100\" width=\"120\" align=\"center\"><b>$username</b><br /><img src=\"" $userinfo['profilepicurl'] . "\" alt=\"\" title=\"$userinfo[username]'s picture\" border=\"0\"";
   
$userinfopic .= ($userinfo['ppwidth'] AND $userinfo['ppheight']) ? " width=\"$userinfo[ppwidth]\" height=\"$userinfo[ppheight]\" " '';
   
$userinfopic .= "/></td>";
 } 

So I use $userinfopic to display the images and I added a query to determine the number of rows. I tried using this in my template:

HTML Code:

<if condition="$user_count > '5'">
</tr><tr>
</if>

But it's being added after userinfopic, so it's obviously not having an effect on the 6th image. If it's not obvious by now, I'm clueless as to how to proceed. If someone wouldn't mind pointing me in the right direction, it'd be much appreciated.

calorie 06-25-2006 01:27 PM

Consider setting a counter and then use something like follows:
Code:

if ($counter % 5 == 0)
{
        // do </tr><tr> thing
}


Kirk Y 06-25-2006 05:17 PM

That's sort of what I was trying, only problem is, I'm not sure where to stick the if condition.

Paul M 06-25-2006 06:30 PM

After the final line, before the closing bracket I would guess.

You also need the $counter - setting it to 0 before the while, and adding 1 to it inside the loop.

Kirk Y 06-25-2006 08:38 PM

$counter would be the same as my $user_count var, would it not?

Guest190829 06-25-2006 09:41 PM

Nope, your $user_count is the amount of rows in the database. $counter will act as a counter, and increment every time the while loop is processed.

So in your while loop you need:

PHP Code:

$counter += 1

if ($counter == 0)
{
    
// do </tr><tr> thing


The "$counter % 5 == 0" expression means if the counter is divisible by 5, then start a new row.

Kirk Y 06-26-2006 12:53 AM

Well it seems like I've done everything right, but I still can't get the pictures to break after the 5th. But thanks for all your collective attempts.

The code works fine, it must be something with my html, as far as I can tell. Would it be more than a </tr><tr>?


All times are GMT. The time now is 01:06 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01057 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete