LexHammer Posted November 26, 2009 Share Posted November 26, 2009 Hello, i have a table that shows users only if I, as Administrator, want to be shown. But its showing just 1 user and i want to show at least 4. If i copy the code, or use loop, its showing the same user 4 times... How to make it show 4 different users? I tried with "LIMIT 1" changed to LIMIT 4, but nothing happens. Here are the codes: PHP code <?php ////////GET LANG IDS $aValues = array(); $sSql = " SELECT `languagevar_id`, REPLACE(`defVarName`, 'home.', '') AS `key` FROM `advFetMem_settings` WHERE `defVarName` LIKE '%home.%' "; $rResult = mysql_query($sSql); while( ($aRow=mysql_fetch_assoc($rResult)) ) $aValues[ $aRow['key'] ] = $aRow['languagevar_id']; $smarty->assign('aCusLang_advFetMem', $aValues); //GET SETTING $sql ="SELECT `setting_username` FROM `se_settings` LIMIT 1"; $result = mysql_query($sql); $aRow = mysql_fetch_assoc($result); $bUserNames = $aRow['setting_username'] == 1 ? TRUE : FALSE; $iTime = time(); $sql = "SELECT `u`.`user_id` AS `userId` FROM `advFetMem_info` AS `i` INNER JOIN `se_users` AS `u` ON `u`.`user_id` = `i`.`userid` WHERE '".$iTime."' BETWEEN `i`.`start` AND `i`.`end` ORDER BY RAND() LIMIT 1"; $result = mysql_query($sql); $smarty->assign('aAdvFetMem', FALSE); if( $aRow = mysql_fetch_assoc($result)) { $tempUser = new se_user(Array($aRow['userId'])); $tempUser->user_displayname(); $aRow['username'] = $tempUser->user_info['user_displayname']; $aRow['photo'] = $tempUser->user_photo("./images/nophoto.gif", TRUE); $smarty->assign('aAdvFetMem', $aRow); } ?> TPL code {* include_advFetMem_home.tpl 2009-07-21 12:57:53 rhutton *} {if $aAdvFetMem} <div class='header'>{lang_print id=$aCusLang_advFetMem.featured_member}</div> <div class='portal_content'> <table cellpadding='0' cellspacing='0' align='center'> <tr> <td class='portal_member' valign="bottom" style="width:50%;"> <a href='./profile.php?user_id={$aAdvFetMem.userId}'>{$aAdvFetMem.username|truncate:15:"...":true}</a><br /> <a href='./profile.php?user_id={$aAdvFetMem.userId}'><img src='{$aAdvFetMem.photo}' class='photo' width='60' height='60' border='0' alt='' /></a><br /> </td> </tr> </table> </div> <div class='portal_spacer'></div> {/if} Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/ Share on other sites More sharing options...
JonnoTheDev Posted November 26, 2009 Share Posted November 26, 2009 If using smarty then you need to build an array of users and then pass it into the template. You will then require a foreach construct to display the data $users = array(); $result = mysql_query("SELECT setting_username FROM se_settings LIMIT 4"); while($row = mysql_fetch_assoc($result)) { $users[] = $row; } $smarty->assign('users', $users); Then in your tpl {foreach item=user from=$users}{$user.setting_username}{/foreach} Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/#findComment-965938 Share on other sites More sharing options...
LexHammer Posted November 26, 2009 Author Share Posted November 26, 2009 I'm newbie to php so could you pls tell me, do i have to just insert them in the other code or i have to do some other coding as well? Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/#findComment-965958 Share on other sites More sharing options...
LexHammer Posted November 27, 2009 Author Share Posted November 27, 2009 When i insert the codes, i get only "1" (number 1 digit) on the top or on the bottom of the table, where the user is shown. But its till just 1 user! Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/#findComment-966395 Share on other sites More sharing options...
LexHammer Posted November 30, 2009 Author Share Posted November 30, 2009 When i insert the codes, i get only "1" (number 1 digit) on the top or on the bottom of the table, where the user is shown. But its till just 1 user! Help...anybody? Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/#findComment-968018 Share on other sites More sharing options...
JonnoTheDev Posted November 30, 2009 Share Posted November 30, 2009 Add your user objects to an array and then loop out in the template. Use the objects methods in the template i.e. user_displayname(); <?php $aValues = array(); $rResult = mysql_query("SELECT languagevar_id, REPLACE(`defVarName`, 'home.', '') AS key FROM advFetMem_settings WHERE defVarName LIKE '%home.%'"); while($aRow = mysql_fetch_assoc($rResult)) { $aValues[$aRow['key']] = $aRow['languagevar_id']; } $smarty->assign('aCusLang_advFetMem', $aValues); // obtain settings $result = mysql_query("SELECT setting_username FROM se_settings LIMIT 1"); $aRow = mysql_fetch_assoc($result); $bUserNames = $aRow['setting_username'] == 1 ? TRUE : FALSE; // users $iTime = time(); $result = mysql_query("SELECT `u`.`user_id` AS `userId` FROM `advFetMem_info` AS `i` INNER JOIN `se_users` AS `u` ON `u`.`user_id` = `i`.`userid` WHERE'".$iTime."' BETWEEN `i`.`start` AND `i`.`end` ORDER BY RAND()"); $smarty->assign('aAdvFetMem', FALSE); $users = array(); while($row = mysql_fetch_assoc($result)) { $users[] = new se_user(array($row['userId'])); } $smarty->assign('users', $users); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/#findComment-968057 Share on other sites More sharing options...
JonnoTheDev Posted December 1, 2009 Share Posted December 1, 2009 i.e loop the users out within the template with a foreach construct {foreach item=user from=$users} {$user->user_displayname()}<br /> {/foreach} If you are not familiar with the code then I suggest you learn from a book or online. http://smarty.net Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/#findComment-968802 Share on other sites More sharing options...
LexHammer Posted December 1, 2009 Author Share Posted December 1, 2009 Not working... the whole table disappear when i insert the php code. Quote Link to comment https://forums.phpfreaks.com/topic/183004-how-to-show-more-than-1-users-with-this-code/#findComment-968852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.