vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Removing trailing comma in loop? (https://vborg.vbsupport.ru/showthread.php?t=174738)

RetroDreams 03-31-2008 09:30 PM

Removing trailing comma in loop?
 
I've got a ranking script using the query below.

PHP Code:

$othervotes $db->query_read("SELECT team, rankem_team.teamid, sum(points) AS totalpoints
FROM rankem_rank
INNER JOIN rankem_team ON rankem_team.teamid = rankem_rank.teamid
WHERE rankem_rank.weekid = 
$week
GROUP BY rankem_team.teamid
ORDER BY totalpoints DESC 
LIMIT 25,100"
);
if (
$db->num_rows($othervotes) > 0)
{
while (
$others $db->fetch_array($othervotes))
{
eval(
'$otherbits .= "' fetch_template('rank_otherbits') . '";');
}


Here is what is in the rank_otherbits template

PHP Code:

$others[team$others[totalpoints], 

As you can guess, there is a trailing comma. Is there a template conditional I can use to strip the last comma? If not, how can I do so programatically?

Boofo 03-31-2008 11:05 PM

Try:

$otherbits .= ', ' . trim($otherbits);

RetroDreams 04-01-2008 12:02 AM

Quote:

Originally Posted by Boofo (Post 1479524)
Try:

$otherbits .= ', ' . trim($otherbits);

Pardon my ignorance, but where exactly is it placed? I've put it before, in and after the loop and nothing formats correctly.

Boofo 04-01-2008 12:08 AM

After.

RetroDreams 04-01-2008 12:10 AM

Like so, right?

PHP Code:

$othervotes $db->query_read("SELECT team, rankem_team.teamid, sum(points) AS totalpoints
FROM rankem_rank
INNER JOIN rankem_team ON rankem_team.teamid = rankem_rank.teamid
WHERE rankem_rank.weekid = 
$week
GROUP BY rankem_team.teamid
ORDER BY totalpoints DESC 
LIMIT 25,100"
);
if (
$db->num_rows($othervotes) > 0)
{
while (
$others $db->fetch_array($othervotes))
{
eval(
'$otherbits .= "' fetch_template('rank_otherbits') . '";');
}
}
$otherbits .= ', ' trim($otherbits); 

Here it is in action... it duplicates the list and adds a space.

http://www.goldhelmet.com/rankings.php?week=1

Boofo 04-01-2008 12:13 AM

$otherbits = ', ' . trim($otherbits);

Sorry

RetroDreams 04-01-2008 12:17 AM

Hmm, still no go. Wondering if it is something wrong with my if statement.

Boofo 04-01-2008 12:19 AM

Put this above the eval:

$otherbits .= ', ' . trim($otherbits);

RetroDreams 04-01-2008 12:24 AM

No go. Duplicates the list numerous times. I tried without the . as well and it just prints like n number of ,s and then the list as it did before.

--------------- Added [DATE]1207013300[/DATE] at [TIME]1207013300[/TIME] ---------------

Got it. I placed $otherbits = trim($otherbits, ', '); after the loop and it got the rangly rascal! Thanks for the gentle kick in the arse!

Boofo 04-01-2008 12:48 AM

Above the eval, right?


All times are GMT. The time now is 04:12 PM.

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.01038 seconds
  • Memory Usage 1,742KB
  • 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
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete