News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Echoing a code left to right in columns

Started by Biology Forums, April 06, 2012, 02:00:13 PM

Previous topic - Next topic

Antechinus

Well, tbh it may need a little tweaking on the styling since I didn't test it live, on account of the PHP containing a lot of custom stuff that would only throw errors on my local site. However, it should be pretty close.

Biology Forums

Quote from: IchBin™ on April 08, 2012, 05:07:33 PM
Your code is pretty ugly. But the more you do it, the more you'll become anal about it as you'll find most of us are. :D

If ants doesn't work ( haven't looked at his) give this a shot.

<?php
function ssi_membergroupadmins($groupid 1$additional 0$sort 1$sortorder 1$output_method 'echo')
{
global $db_prefix$user_info$scripturl$modSettings$txt$sc;
//-- $mgroup = Group Number
//-- $Additional = Search Additional Groups as well
//-- $sort = How to sort the names. ID Number(2) or realname(1 default).
//-- $sortorder = Sort ASC or DESC

//Lets get some checks done for the sake of the script not returning errors
//if the groupids are array we need to make them valid.
if(is_array($groupid))
$groupid array_map('intval',$groupid);

//Well the groupid is a single id.. lets make it valid..
if(!is_array($groupid))
$groupid = (int) $groupid;

//Either its off or its on.. Should also stop use of array..
if(($additional !=&& $additional !=1) || ($sort !=&& $sort !=1) || ($sortorder !=&& $sortorder !=1))
fatal_error('Invalid Input for this ssi_function');

//We shouldn't be getting Group 0. Fix it by Showing Admin Group..
if($groupid == 0)
$groupid 1;

//Set our output to something its better than nothing.
$membergroup = array();

//Find out if our groups we are looking at is in an array or not..
if(is_array($groupid))
{
//Array has multiple groups so if we want to search additional as well we have to loop it.
if(isset($additional) && $additional != 0)
{
//lets just clear additional instead of a new variable.
$additional '';
foreach($groupid as $add)
$additional .= '
OR FIND_IN_SET('
.$add.', additionalGroups)';
}
$request db_query("
SELECT ID_MEMBER, realname, ID_GROUP, avatar, karmaBad, karmaGood, emailAddress, posts
FROM 
{$db_prefix}members
WHERE ID_GROUP IN (" 
implode(', ',$groupid) . ")".$additional."
ORDER BY '"
.($sort == 'ID_MEMBER' 'realname')."' ".($sortorder == 'DESC' 'ASC').""__FILE____LINE__);
}
else
$request db_query("
SELECT ID_MEMBER, realname, ID_GROUP, avatar, karmaBad, karmaGood,  emailAddress, posts, thank_you_post_became, thank_you_post_made, money, shop_Flag, personalText, dateRegistered, lastLogin
FROM 
{$db_prefix}members
WHERE ID_GROUP = " 
$groupid . ($additional == "
OR FIND_IN_SET(" 
$groupid ", additionalGroups)" "")."
ORDER BY '"
.($sort == 'ID_MEMBER' 'realname')."' ".($sortorder == 'DESC' 'ASC').""__FILE____LINE_);

//We got the query. Now lets get it into a nice little array..
while ($row mysql_fetch_assoc($request))
$membergroup[] = array(
'id' => $row['ID_MEMBER'],
'name' => $row['realname'],
'group' => $row['ID_GROUP'],
'post' => $row['posts'],
'href' => $scripturl '?action=profile;u=' $row['ID_MEMBER'],
'avatar' => array(
             
'image' => stristr($row['avatar'], 'http://') ? 'src="' $row['avatar'] . '" alt="Profile Display Picture" border="0" />' 'src="' $modSettings['avatar_url'] . '/' htmlspecialchars($row['avatar']) . '" alt="Profile Display Picture" border="0" />',
          ),
  'karmaGood' => $row['karmaGood'],
'karmaBad' => $row['karmaBad'],
'karmaTotal' => $row['karmaGood'] - $row['karmaBad'],
'mail' => $row['emailAddress'],
'login' => $row['lastLogin'],
'registered' => $row['dateRegistered'],
'status' => $row['personalText'],
'flag' => $row['shop_Flag'],
'thank_you_post_became' => $row['thank_you_post_became'],
'money' => $row['money'],
'thank_you_post_made' => $row['thank_you_post_made']
);
mysql_free_result($request);

//If they dont want to echo.. So lets give it to them..
if ($output_method != 'echo')
return $membergroup;

echo'
<table width="100%">
<tr>'
;

$counter 0;
$columns 2;
//Well they want it echo so lets echo...
foreach ($membergroup as $mem) {
loadMemberData($mem['id']);
loadMemberContext($mem['id']);
global $memberContext
echo '
<td width="50%">
<div style="padding: 1ex; font-size: 0.9em; line-height: 15px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: #ADADAD; border-right-color: #ADADAD; border-bottom-color: #ADADAD; border-left-color: #ADADAD; border-image: initial; background-color: #ECEDF3; background-attachment: initial; background-origin: initial; background-clip: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 1ex; margin-left: 0px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; border-radius:5px; color: rgb(0, 0, 0); font-family: arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-position: initial initial; background-repeat: initial initial;">
<div class="windowbg">
<table width="100%">
<tr>
<td>
<a href="'
.$scripturl.'?action=profile;u='.$mem['id'].'" class="ssi_membergroup" id="ssi_member_'.$mem['id'].'"><span style="font-weight: bold; text-transform: capitalize;">'.$mem['name'].'</span></a>';

if(!empty($mem['flag']))
echo'
<img src="http://biology-forums.com/Sources/shop/flag_images/'
.$mem['flag'].'" alt="flag">';

if($groupid == || $groupid == 3)
echo' - Moderator';

if($groupid == 13)
echo' - Trusted Seller';

if($groupid == 1)
echo' - Administrator';

if($groupid == 15)
echo' - Contributor of the Month';

if(!empty($mem['status']))
echo'
<br /><small><b>Status:</b> <i>'
.$mem['status'].'</i></small>';

echo'
</td>
<td width="75" style="padding-left: 1ex; align: center;">
<center>'
,empty($memberContext[$mem['id']]['avatar']['image']) ? 
'<img src="'.$settings['images_url'].'/noavatar.gif" width="50" height="50" />' :
'<img height="50" width="50" src="' $memberContext[$mem['id']]['avatar']['href'] . '"  alt="'.$mem['name'].'" />';
echo '
</center>
</td>
</tr>
</table>'
;
 
   echo'
<ul style="list-style-image:url(http://icons.primail.ch/bullets/c001.gif); padding-top: 0ex; margin-top: 0px;">'
;
   
if($mem['karmaTotal'] > 0)
echo'
<li><b>Reputation:</b> <font color="green">'
.$mem['karmaTotal'].'</font></li>';

if($mem['karmaTotal'] < 0)
echo'
<li><b>Reputation:</b> <font color="red">'
.$mem['karmaTotal'].'</font></li>';

echo'
<li><b>Posts:</b> <font color="navy">'
.$mem['post'].'</font></li>
<li><b>Best answer votes recieved:</b> '
.$mem['thank_you_post_became'].'</li>
<li><b>Points Earned:</b> '
.$mem['money'].'</li>
<li><b>Team member since</b> ' 
timeformat($mem['registered']). '</li>
<li><b>Last active</b> ' 
timeformat($mem['login']). '</li>
<li>Send a <a href="http://biology-forums.com/index.php?action=pm;sa=send;u='
.$mem['id'].'">personal message</a></li>';

echo'
</ul>
</div>
</div>
</td>'
;
if ($columns $counter == 0)
echo '
</tr>
<tr>'
;

$counter++;
 }

echo'
</tr>
</table>'
;
}


Thanks for the honesty, IchBin. Problem though, it still isn't inputting the members in columns of 2 :( It is still like this:

X
X
X
X
X

Instead of

XX
XX
XX

http://biology-forums.com/index.php?action=Tester

This is what your code produces.

Marcus Forsberg

Did you try Ant's code at all? It looks good to me and, as he's been trying to say, it's a heck of a lot better to use CSS (and external CSS, not inline!) than tables.

IchBin™

haha, I bet at first Ant you were probably like "wtf" until I specified I wasn't talking about your code. lol

Updated my code after I actually tested it. :D
IchBin™        TinyPortal

Biology Forums

Quote from: Marcus Forsberg on April 09, 2012, 04:26:33 AM
Did you try Ant's code at all? It looks good to me and, as he's been trying to say, it's a heck of a lot better to use CSS (and external CSS, not inline!) than tables.

Yes, I ended up trying it and it looks like this:

http://biology-forums.com/index.php?action=staff

It's perfect, but I wish the blocks where a bit wider for each member.

Still waiting on IchBin™ to see if his table version will work.

IchBin™

Quote from: Liam_michael on April 09, 2012, 12:19:59 PM

Still waiting on IchBin™ to see if his table version will work.

As I just said in my post before yours, I updated my code. Check the post where I posted the code and you'll see a couple of changes. :)
IchBin™        TinyPortal

Biology Forums

Quote from: IchBin™ on April 09, 2012, 01:29:08 PM
Quote from: Liam_michael on April 09, 2012, 12:19:59 PM

Still waiting on IchBin™ to see if his table version will work.

As I just said in my post before yours, I updated my code. Check the post where I posted the code and you'll see a couple of changes. :)

Looks great, thanks to both IchBin and Antechinus

@IchBin, when there is only 1 person in the membergroup... See http://biology-forums.com/index.php?action=staff (All the way at the bottom), it spreads the block all the way 100%.

How do I change it so that the block for that one member is the same as everyone else?

Is that possible?

IchBin™

You'll have to change the html and stuff to not display it 100%. I think you have some tables in their set to display 100%.
IchBin™        TinyPortal

Biology Forums

Quote from: IchBin™ on April 09, 2012, 02:15:37 PM
You'll have to change the html and stuff to not display it 100%. I think you have some tables in their set to display 100%.

True,

I tried this:

echo'
<table

', $membergroup == '1' ? 'width="50%"' : 'width="100%"','><tr>';


But it didn't work.

IchBin™

IchBin™        TinyPortal

Biology Forums

Quote from: IchBin™ on April 09, 2012, 02:58:20 PM
I think you mean $mem['id'] == '1'

No, no... That's called after words:

echo'
<table ', $membergroup == '1' ? 'width="50%"' : 'width="100%"','>
<tr>';

$counter = -1;
$columns = 2;
//Well they want it echo so lets echo...
foreach ($membergroup as $mem) {
loadMemberData($mem['id']);
loadMemberContext($mem['id']);
global $memberContext;
echo '
<td width="50%">
.
.
.


With my attempt, I'm trying to tell the computer that if there is only 1 person in the membergroup, make the parent table 50% instead of 100%.

Antechinus

Question: if mine was perfect, why on earth would you want to use a table version with inline css?

Also, my code would automatically make all blocks the same width on all rows, regardless of how many blocks you put on each row.

Biology Forums

Quote from: Antechinus on April 09, 2012, 05:18:23 PM
Question: if mine was perfect, why on earth would you want to use a table version with inline css?

Also, my code would automatically make all blocks the same width on all rows, regardless of how many blocks you put on each row.

Good question. Here's why... if, for instance, one member's block had more information than the next member in the membergoup (so essentially increasing the height of a single block), it would not automatically adjust the next person's block. As a result, the next member would be forced to show up in a new row. Hard to explain on paper, but if I can't get IchBin™ to fix this little problem, I will go back to your code, since it's only a small sacrifice.


Antechinus

Ah. Well that wouldn't be hard to fix if I could see it running live. As I said, due to the amount of custom code you were running I didn't actually test anything live, because it would just have thrown a lot of errors on my test site.

Biology Forums

Quote from: Antechinus on April 09, 2012, 05:50:15 PM
Ah. Well that wouldn't be hard to fix if I could see it running live. As I said, due to the amount of custom code you were running I didn't actually test anything live, because it would just have thrown a lot of errors on my test site.

Oh true, here's a live example of your code (http://biology-forums.com/index.php?action=staff)

Check out Biolove and see what happens. :'(

Here's your code in full effect :D

// Show From all from a member group. Great for Rosters.
function ssi_membergroupadmins($groupid = 1, $additional = 0, $sort = 1, $sortorder = 1, $output_method = 'echo')
{
global $db_prefix, $user_info, $scripturl, $modSettings, $txt, $sc;
//-- $mgroup = Group Number
//-- $Additional = Search Additional Groups as well
//-- $sort = How to sort the names. ID Number(2) or realname(1 default).
//-- $sortorder = Sort ASC or DESC

//Lets get some checks done for the sake of the script not returning errors
//if the groupids are array we need to make them valid.
if(is_array($groupid))
$groupid = array_map('intval',$groupid);

//Well the groupid is a single id.. lets make it valid..
if(!is_array($groupid))
$groupid = (int) $groupid;

//Either its off or its on.. Should also stop use of array..
if(($additional !=0 && $additional !=1) || ($sort !=2 && $sort !=1) || ($sortorder !=2 && $sortorder !=1))
fatal_error('Invalid Input for this ssi_function');

//We shouldn't be getting Group 0. Fix it by Showing Admin Group..
if($groupid == 0)
$groupid = 1;

//Set our output to something its better than nothing.
$membergroup = array();

//Find out if our groups we are looking at is in an array or not..
if(is_array($groupid))
{
//Array has multiple groups so if we want to search additional as well we have to loop it.
if(isset($additional) && $additional != 0)
{
//lets just clear additional instead of a new variable.
$additional = '';
foreach($groupid as $add)
$additional .= '
OR FIND_IN_SET('.$add.', additionalGroups)';
}
$request = db_query("
SELECT ID_MEMBER, realname, ID_GROUP, avatar, karmaBad, karmaGood,  emailAddress, posts, thank_you_post_became, thank_you_post_made, money, shop_Flag, personalText, dateRegistered, lastLogin
FROM {$db_prefix}members
WHERE ID_GROUP IN (" . implode(', ',$groupid) . ")".$additional."
ORDER BY '".($sort == 2 ? 'ID_MEMBER' : 'realname')."' ".($sortorder == 2 ? 'DESC' : 'ASC')."", __FILE__, __LINE__);
}
else
$request = db_query("
SELECT ID_MEMBER, realname, ID_GROUP, avatar, karmaBad, karmaGood,  emailAddress, posts, thank_you_post_became, thank_you_post_made, money, shop_Flag, personalText, dateRegistered, lastLogin
FROM {$db_prefix}members
WHERE ID_GROUP = " . $groupid . ($additional == 1 ? "
OR FIND_IN_SET(" . $groupid . ", additionalGroups)" : "")."
ORDER BY '".($sort == 2 ? 'ID_MEMBER' : 'realname')."' ".($sortorder == 2 ? 'DESC' : 'ASC')."", __FILE__, __LINE__);

//We got the query. Now lets get it into a nice little array..
while ($row = mysql_fetch_assoc($request))
$membergroup[] = array(
'id' => $row['ID_MEMBER'],
'name' => $row['realname'],
'group' => $row['ID_GROUP'],
'post' => $row['posts'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'avatar' => array(
             'image' => stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="Profile Display Picture" border="0" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="Profile Display Picture" border="0" />',
          ),
  'karmaGood' => $row['karmaGood'],
'karmaBad' => $row['karmaBad'],
'karmaTotal' => $row['karmaGood'] - $row['karmaBad'],
 
'mail' => $row['emailAddress'],
'login' => $row['lastLogin'],
'registered' => $row['dateRegistered'],
'status' => $row['personalText'],
'flag' => $row['shop_Flag'],
'thank_you_post_became' => $row['thank_you_post_became'],
'money' => $row['money'],
'thank_you_post_made' => $row['thank_you_post_made']
);
mysql_free_result($request);

//If they dont want to echo.. So lets give it to them..
if ($output_method != 'echo')
return $membergroup;
global $settings;
echo'

<style>/* This should work. Better than tables. */
/* Seriously, you should try it. :D */

#member_blocks_wrapper {
list-style-type: none;
margin: 5px;
/* This will make the ul wrap floated content, but should not cause scroll bars. */
overflow: auto;
}
#member_blocks_wrapper li.member_containers {
float: left;

/* If you decide you want three blocks per row, change the next value to 33.3% */
/* If you decide you want four blocks per row, change the next value to 25% */
width: 50%;
/* The next three are necessary to prevent content paddings being added to overall width. */
/* IE8+ and Opera accept the basic W3 syntax. Firefox and Safari/Chrome still require prefixes. */
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
ul.member_blocks {
margin: 5px;
list-style-type: none;
padding: 1em;
font: 0.9em/1.3em "Arial", "Helvetica", sans-serif;
background: #ECEDF3;
color: #000;
border: 1px solid #ADADAD;
border-radius:5px;
orphans: 2;
widows: 2;
}
li.member_name {
float: left;
}
li.member_name a {
font-weight: bold;
text-transform: capitalize;
}
li.member_name div {
font-weight: bold;
font-size: 0.9em;
}
li.member_name div span {
font-weight: normal;
font-style:italic;
}
li.member_rep, li.member_posts, li.member_votes,
li.member_points, li.member_since, li.member_active {
font-weight: bold;
}
li.member_rep span, li.member_posts span, li.member_votes span,
li.member_points span, li.member_since span, li.member_active span {
font-weight: normal;
}
li.member_avatar {
float: right;
width: 75px;
text-align: center;
padding: 0;
}
.karma_pos {
color: green;
}
.karma_neg {
color: red;
}
li.posts span {
color: navy;
}</style>

<ul id="member_blocks_wrapper">';

//Well they want it echo so lets echo...
foreach ($membergroup as $mem)
{
loadMemberData($mem['id']);
loadMemberContext($mem['id']);
global $memberContext;
echo '
<li class="member_containers">
<ul class="windowbg member_blocks">
<li class="member_name">
<a href="'.$scripturl.'?action=profile;u='.$mem['id'].'" class="ssi_membergroup" id="ssi_member_'.$mem['id'].'">
'.$mem['name'].'
</a>';
if(!empty($mem['flag']))
echo'
<img src="http://biology-forums.com/Sources/shop/flag_images/'.$mem['flag'].'" alt="flag">';
if($groupid == 1)
echo'
- Administrator';
if($groupid == 2 || $groupid == 3)
echo'
- Moderator';
if($groupid == 13)
echo' - Trusted Seller';
if($groupid == 15)
echo'
- Contributor of the Month';
if(!empty($mem['status']))
echo'
<div style="margin-bottom: 0.5ex;">Status:&nbsp;<span>'.$mem['status'].'</span></div>';
echo'
</li>
<li class="member_avatar">


',empty

($memberContext[$mem['id']]['avatar']['image'])

? '<img src="'.$settings['images_url'].'/noavatar.gif" width="50" height="50" />' : '<img height="50" width="50" src="' . $memberContext[$mem['id']]['avatar']['href'] . '"  alt="'.$mem['name'].'" />' ,'

</li>
<li class="member_rep">
<br /><br />Reputation: <span class="', ($mem['karmaTotal'] > 0) ? 'karma_pos' : 'karma_neg', '">'.$mem['karmaTotal'].'</span>
</li>
<li class="member_posts">
Posts: <span>'.$mem['post'].'</span>
</li>
<li class="member_votes">
Best answer votes received: <span>'.$mem['thank_you_post_became'].'</span>
</li>
<li class="member_points">
Points Earned: <span>'.$mem['money'].'</span>
</li>
<li class="member_since">
Team member since: <span>' . timeformat($mem['registered']). '<span>
</li>
<li class="member_active">
Last active: <span>' . timeformat($mem['login']). '</span>
</li>';
if($context['allow_pm'])
echo '
<li class="member_pm">
Send a <a href="'.$scripturl.'?action=pm;sa=send;u='.$mem['id'].'">personal message</a>
</li>';
echo '
</ul>
</li>';
}

echo'
</ul>';
}

Biology Forums

I managed to fix the problem if I added an extra <br /> to the

<br /><br />Reputation:

Is there another way though?

http://biology-forums.com/index.php?action=staff

Antechinus

Ah. Yup that would be a problem with the floats for the top section. I'll put the markup and css on a test page tonight with some filler content that doesn't rely on your variables, and play around with it a bit. Should be easy enough.

Biology Forums

Quote from: Antechinus on April 09, 2012, 06:53:16 PM
Ah. Yup that would be a problem with the floats for the top section. I'll put the markup and css on a test page tonight with some filler content that doesn't rely on your variables, and play around with it a bit. Should be easy enough.

Thanks plenty, Antechinus.

Advertisement: