Customizing SMF > SMF Coding Discussion
Echoing a code left to right in columns
Liam_michael:
--- Quote from: IchBin™ on April 07, 2012, 10:44:52 PM ---Liam_michael,
In order to make a column to your specification you need some type of counter. This can be done a few ways, but I'll show one way.
First is to create a counter variable and then to check the value of it. If the value divided by the count of columns you want has a remainder of 0, then you create a new column. Here's a quick code mock-up since it's kind of hard to explain.
--- Code: ---$number_of_columns = 2;
$counter = 0;
echo '
<table>';
foreach ($membergroup as $mem) {
// loop through your $mem stuff and create your rows
echo '
<tr>
<td> Do stuff for first column</td>
<td> Do stuff for second column</td>';
if ($counter % $number_of_rows == 0) {
// if the counter divided by number of rows has a remainder of 0 end current row and add another row.
echo '
</tr>
<tr>';
}
// Add 1 to the counter
$counter++;
}
--- End code ---
--- End quote ---
Thanks IchBin™, you actually understand what it is I'm looking to accomplish!
Could you set it up in terms of this code?
--- Code: ---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
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;
echo' <table width="100%"><tr>';
//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 == 2 || $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'].'" /></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>';
}
echo'</tr></table>';
}
--- End code ---
Antechinus:
Hey, try this. :D Srsly.
The PHP:
--- Code: ---global $MemberData, $memberContext, $scripturl, $membergroup, $mem, $groupid, $context;
echo'
<ul id="member_blocks_wrapper">';
//Well they want it echo so lets echo...
foreach ($membergroup as $mem)
{
loadMemberData($mem['id']);
loadMemberContext($mem['id']);
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>Status: <span>'.$mem['status'].'</span></div>';
echo'
</li>
<li class="member_avatar">
', ($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">
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>';
--- End code ---
The CSS:
--- Code: ---/* This should work. Better than tables. */
/* Seriously, you should try it. :D */
#member_blocks_wrapper {
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;
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;
}
--- End code ---
IchBin™:
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.
--- Code: ---<?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 !=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
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;
echo'
<table 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%">
<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 == 2 || $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 ($counter % $columns == 0)
echo '
</tr>
<tr>';
$counter++;
}
echo'
</tr>
</table>';
}
--- End code ---
Antechinus:
--- 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......................
--- End quote ---
:P :P :D
N. N.:
--- 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
--- End quote ---
* Norv rolls on the chair laughing.
(sorry for interjecting, couldn't help it lol. Nice job there. :D)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version