vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Dynamic code for collapsible boxes error on ']' (https://vborg.vbsupport.ru/showthread.php?t=168921)

petteyg359 01-28-2008 03:11 AM

Dynamic code for collapsible boxes error on ']'
 
I get the error "Parse error: syntax error, unexpected '"', expecting ']' in /home/dysplace/public_html/eve-ocf/eveit.php on line 161" when trying to run
PHP Code:

$corp "ocf";
$ocfapidata "<tbody><tr><td class=\"thead\" colspan=\"3\"><a style=\"float:".$stylevar[right]."\" href=\"#top\" ";
$ocfapidata .= "onclick=\"return toggle_collapse('359_eveit_".$i."')\"><img id=\"collapseimg_359_eveit_".$i."\" ";
//OFFENDING LINE BELOW
$ocfapidata .= "src=\"".$stylevar[imgdir_button]."/collapse_thead$vbcollapse[collapseimg_359_eveit_".$i."].gif\" alt=\"\" ";
//OFFENDING LINE ABOVE
$ocfapidata .= "border=\"0\" /></a>".$attr[$corp]['charactername']."</td></tr></tbody><tbody id=";
$ocfapidata .= "\"collapseobj_359_eveit_".$i."\" style=\"\$vbcollapse[collapseobj_359_eveit_".$i."]\"><tr><td class=\"alt1\$
$ocfapidata .= "Character: <font color=\"#FF7800\">".$attr[$corp][$i]['charname']."</font><br />";
$ocfapidata .= "</font></td><td class=\"alt1\">";
$ocfapidata .= $skills[$sit[$corp][$i]['trainid']]['name'];
$ocfapidata .= " ".$sit[$corp][$i]['trainto']."</td><td class=\"alt1\">".$sit[$corp][$i]['trainleft']."</td></tr>";
$ocfapidata .= "</tbody>"

I have $ocfapidata in my template, and it displays just fine when I change the offending line to
PHP Code:

$ocfapidata .= "src=\"".$stylevar[imgdir_button]."/collapse_thead$vbcollapse[collapseimg_359_eveit_0].gif\" alt=\"\" "

except for that the 0 being there means only the last output box is displayed.

None of the other similar lines cause a problem, but as I am looping through an array to display, I need that eveit_$i].gif rather than eveit_0].gif. I could put a switch case for every line, but that'd be rather inefficient with many users.

Any suggestions on how to get around that error? I've tried using {$i} in the code, same error. It really doesn't want me to use a variable there, for some reason. I know $i has a value, if I place echo $i; in my code I get 012345678910 at the top of my page.


One other slightly unrelated question, when the collapsible box is collapsed, there's no title on the bar that the image is on that signifies what is in the box. Is there a way to give the box some header text?

MoT3rror 01-28-2008 03:37 AM

Try to quote out $vbcollapse[collapseimg_359_eveit_0] like this if you can.
PHP Code:

$ocfapidata .= "src=\"".$stylevar[imgdir_button]."/collapse_thead" $vbcollapse[collapseimg_359_eveit_0]. ".gif\" alt=\"\" "


petteyg359 01-28-2008 02:21 PM

I changed that line to
PHP Code:

$ocfapidata .= "src=\"".$stylevar[imgdir_button]."/collapse_thead";
$collapsenum "collapseimg_359_eveit_".$ig;
$ocfapidata .= $vbcollapse[$collapsenum]; 

and it got rid of the error. I found the reason the boxes weren't repeating :) That first line in the code had = rather than .=, which is now fixed, and the page is working fine. I'd still like to have a header on collapsed tbody, though...

Opserty 01-28-2008 02:54 PM

Argh that is some ugly code, when you are writing a lot of HTML into PHP strings use single quotes that way you don't need to escape every double quote in the HTML.

For example:
PHP Code:

$ocfapidata "<tbody><tr><td class=\"thead\" colspan=\"3\"><a style=\"float:".$stylevar[right]."\" href=\"#top\" ";
// BECOMES:
$ocfapidata '<tbody><tr><td class="thead" colspan="3"><a style="float:'$stylevar['right'] .'" href="#top" '

Doesn't it look so much better? :p

petteyg359 01-28-2008 07:45 PM

1 Attachment(s)
Fixed my code just for you. Happy? :P

Anyway, have a slight problem with the boxes still. Figure it'd be easier to figure out if I post the whole code block. So here it is:
PHP Code:

$apidata = Array();
for (
$ih 0$ih $numcorps$ih++) {
if (
$ih == 0) { $corp "ocf"; }
for (
$i 0$i < ($num[$corp]); $i++) {
$collapse[$corp] = "collapseimg_359_eveit_".$i;
$collapseb[$corp] = 'collapseimg_359_eveit_'.($i $num[$corp]);

$apidata[$corp] .= '<tbody>';
$apidata[$corp] .= '<tr><td class="thead" colspan="4"><a style=';
$apidata[$corp] .= '"float:'.$stylevar['right'].'" href="#top" ';
$apidata[$corp] .= 'onclick="return toggle_collapse(\'359_eveit_'.$i.'\')">';
$apidata[$corp] .= '<img id="collapseimg_359_eveit_'.$i.'" ';
$apidata[$corp] .= 'src="'.$stylevar['imgdir_button'].'/collapse_thead';
$apidata[$corp] .= $vbcollapse[$collapse[$corp]].'.gif" ';
$apidata[$corp] .= 'alt="" border="0" /></a>';
$apidata[$corp] .= $attr[$corp][$i]['charname'].'</td></tr></tbody><tbody id=';
$apidata[$corp] .= '"collapseobj_359_eveit_'.$i.'" style="';
$apidata[$corp] .= $vbcollapse[collapseobj_359_eveit_'.$i.']">';

$apidata[$corp] .= '<tr>';
$apidata[$corp] .= '<td width="15%" class="alt1"><font color="#FF7700">Skill In Training:</font></td>';
$apidata[$corp] .= '<td width="15%" class="alt1">'.$sit[$corp][$i]['trainname'].' '.$sit[$corp][$i]['trainto'].'</td>';
$apidata[$corp] .= '<td width="55%" class="alt1">'.$sit[$corp][$i]['traindesc'].'</td>';
$apidata[$corp] .= '<td width="15%" class="alt1">'.$sit[$corp][$i]['trainleft'].'</td>';
$apidata[$corp] .= '</tr>';

$apidata[$corp] .= '</tbody>';
}


The output is perfectly fine. Until I decide to collapse any box other than the top one, that is. When I collapse any box other than the first one, the right-aligned collapse image turns into an ugly red X. The image source shows as "http://eve-ocf.com/images/omega359-eve/buttons/collapse_thead_collapsed_collapsed.gif". Not sure where it's getting the second _collapsed from.



Also, I'd like to have _nested_ collapsing boxes. I've tried placing another thead/tbody inside the first box (with a different ID of course), and it opens and closes fine (except for the image glitch). However, if it is open and I close the box it is nested in, the text still shows, if it is closed when I close the box it is nested in, then it stays non-visible. Are nested boxes like this possible within the vB code or do I need to add in more javascript for my own boxes?

petteyg359 01-29-2008 01:08 AM

Fixed the image issue by moving $vbcollapse[$collapse[$corp]].'.gif" '; to its own line. Still looking for a way to nest collapsible boxes, anybody know how?


All times are GMT. The time now is 01:01 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.01108 seconds
  • Memory Usage 1,771KB
  • 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
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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