Warning: #1265 Data truncated for column 'singletemplate' at row 1

Warning: #1265 Data truncated for column 'singletemplate' at row 1

Paul Young -
回帖数:8

I was trying to paste the template I developed into the Single template box and received the following message:

"Error writing to database"

Then, I went to phpmyadmin trying to paste the template in the mdl_data table. I received the following message:

"Affected rows: 1
Warning: #1265 Data truncated for column 'singletemplate' at row 1"

BTW, the template has 1057 lines and 74086 characters. Is it because the template is too big?

Thanks! 

回复Paul Young

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Itamar Tzadok -

8551 characters too many. 微笑

回复Itamar Tzadok

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Paul Young -

I thought about using javascript to shorten the template. For examples, ||sid1||, ||sid2||, and ||sid3|| are three text fields. With the following code, 

<script type="text/javascript">
  for (i=1;i<=3;i++) {
  var x="||sid"+i+"||<br>";
  document.write(x);
}  

Instead of three input boxes, I got the following:

||sid1||

||sid2||

||sid3||

 Any suggestion?

回复Paul Young

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Itamar Tzadok -

Before the page is sent to the browser all field tags are replaced. But in your script the tag is broken and so could not be replaced.

Why are you using document.write? What are trying to do? 微笑

回复Itamar Tzadok

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Paul Young -

I will use a simpler task to explain what I was trying to achieve. Suppose my original template looks:

<table>
<tr>
<td>1. Demonstrates very superior intellectual ability</td>
<td>||sa11||</td>
</tr>
</table>

<table>
<tr>
<td>1. Demonstrates very superior intellectual ability</td>
<td>||sa12||</td>
</tr>
</table>

...

<table>
<tr>
<td>1. Demonstrates very superior intellectual ability</td>
<td>||sa19||</td>
</tr>
</table>

Since there is much repetition, I was thinking using javascript to shorten it by writing:

<script type="text/javascript">
for (i=1;i<=9;i++) {
document.write("<table><tr>");
document.write("<td>1. Demonstrates very superior intellectual ability</td>");
document.write("<td>||sid1"+i+"||</td>");
document.write("</tr></table>");
}
</script>

However, as you pointed out, the tag is broken and so could not be replaced. Is it even possible to shorten the template by using javascript loop?

回复Paul Young

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Itamar Tzadok -

Yes, it's possible in various ways.

One important consideration is that the javascript doesn't have to go into the add template. It can be in the javascript template and if it is too long for that template too it can reside in an external js file which you can call either in the add template or in the javascript template.

Judging by your example above, it seems that you can reduce the size of the template considerably by not repeating the 'document.write' clause even if you break down the html writing to separate lines for better readability of the code. Something like:

document.write('<table><tr>
                        <td>1. Demonstrates very superior intellectual ability</td>
                        <td>||sid1'+i+'||</td>
                        </tr></table>');

As for the entry fields, one way to go about it is to dump all the field tags inside the template, each one enclosed in an identified div tag which is set to display:none. This way you will have all the fields hidden in the template and available for further manipulation by javascript.

Then, your document.write loop could look something like:

document.write('<table><tr>
   <td>1. Demonstrates very superior intellectual ability</td>
   <td>'+document.getElementById('sa1'+i).innerHTML+'</td>
</tr></table>');

The document.getElementById('sa1'+i) retreives the eclosing div of the desired field and the innerHTML retreives its content which is the field itself.

And there could be other more or less efficient ways to do all that depending on what your actual template requires.

hth 微笑

回复Itamar Tzadok

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Paul Young -

I tried but cannot even get the following to work:

In Add template:
<div id="fieldtag">sa11</div>

In JS template:
document.write(document.getElementById('sa11').innerHTML);

I also tried the following:
document.write(document.getElementById('||sa11||').innerHTML);
document.write(document.getElementById('||sa11#id||').innerHTML);

None of them worked. 


 

回复Paul Young

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Itamar Tzadok -

Of course. Try document.getElementById('fieldtag').innerHTML.

If you're comfortable with dom you should probably grab the div container of the field and append it to the table you create, rather than copy its content.

If you want better control over where your javascript output goes you should probably get used to not using document.write (unless you have performance issues). Instead, construct strings and assign them to the innerHTML of a specific container element.

Consider that the js template is applied to all views (edit, single, list). So you shouldn't simply write to the document in the js template, but rather wrap the code in functions and call designated functions from the views. If your code should be ran only in the edit view, wrap it in a function and call that function from that view by adding to the template a script tag with a call to that function.

 

hth 微笑

回复Itamar Tzadok

Re: Warning: #1265 Data truncated for column 'singletemplate' at row 1

Paul Young -

document.getElementById('fieldtag').innerHTML worked. Thank you so much!