SimplePortal
Customization => Custom Coding => Topic started by: FireDitto on December 13, 2012, 10:29:46 AM
-
I just wanted to update an option on an already working block, and I got the following error upon saving:
An Error Has Occurred!
Database error in block code. Please check the code.
Like I said; the block is still active and working but... Won't let me update? This is the code I'm using:
$columns = 3;
$block_ids = array(9,11,39);
$block_data = array();
foreach ($block_ids as $block)
{
$block_data[$block] = current(getBlockInfo(false, $block, false, false));
$block_data[$block]['style'] = sportal_parse_style('explode', $block_data[$block]['style'], true);
}
echo '
<table style="width: 100%;">
<tr>';
$counter = 0;
foreach ($block_data as $data)
{
if ($counter != 0 && $counter % $columns == 0)
{
echo '
</tr>
<tr>';
}
echo '
<td style="width: ', ceil((100 / $columns)), '%; vertical-align: top;">
', template_block($data), '
</td>';
$counter++;
}
echo '
</tr>
</table>';
-
I can't reproduce this error on my site, did you tried to disable PHP validation (SimplePortal > General Settings)?
-
FireDitto,
I also find that the php block saves & works as it should. Although I can think of 2 possible issue..
- Ensure the block type you are selecting is indeed php
- The echo command requires periods (not commas) for attributes within quotes using variables/integers
Imo try adjusting this part of the code as such:
echo '
<td style="width: '. ceil((100 / $columns)). '%; vertical-align: top;">
', template_block($data), '
</td>';
For echo you do use commas for separation but not within attribute quotations as it requires a period.
-
FireDitto,
I also find that the php block saves & works as it should. Although I can think of 2 possible issue..
- Ensure the block type you are selecting is indeed php
- The echo command requires periods (not commas) for attributes within quotes using variables/integers
Imo try adjusting this part of the code as such:
echo '
<td style="width: '. ceil((100 / $columns)). '%; vertical-align: top;">
', template_block($data), '
</td>';
For echo you do use commas for separation but not within attribute quotations as it requires a period.
The concatenation of the strings does not matter in this case. Using either a period or a comma in the case of separating variables from output does not effect anything. If anything, all you're doing ultimately using using more concats that you should be, though this is a problem that SMF has in of itself. PHP is forced to re-concatenate with every '.' operator, so it ends up slower. Commas however fix this problem though it does end up looking rather silly.
eg;
Fast:
echo "{$str1}{$str2}{$str3}";
Slow:
echo $str1 . $str2. $str3;
-
ccbtimewiz,
Thank you for the proper terminology & information. Imo in this case the loop would not be large enough to notice any difference when using concat. Please note that I am specifically referring to variables/integers being used within the style attribute quotations and not any other part of the display.
FireDitto,
As I said, the block works for me as it is. I suggested the concat within the style quotes as I have had errors in the past using a comma where using concat solved the problem. It will not hurt to try to see if the change will allow you to save the php block code. I do not suggest disabling PHP validation as the code should validate if there are no issues/errors with it.