php - How to append html tags every three rows of a table that is being dynamically generated using Jquery -


is there way can use jquery insert '' tags after every 3 dynamically generated table cells end dynamic 3 column table?

please excuse lack of knowledge, i'm literally trying write first jquery script ever, know absolutely nothing. know php , have table has loop within dynamically creating <td></td> information inside each tag. in other words dynamically creating table cells within static <tr></tr> tag. problem keeps outputing tables without breaking them rows leaves me bunch of columns. i've read other articles on none seem have exact same problem do, , still struggling understand how write custom jquery code.

the php code long , full of numerous if statements , other functions i'm not going post here make little simpler, made miniature mockup of i'm trying do.

            <table id="mytable" width="266" border="1" cellspacing="10" cellpadding="10">               <tr>             <?php             $x=0;             while (have_products($x)) {                 echo '<td>' . somelongassfunction() . '</td>';                 $x++;             if (fmod($x,3) == 0) {                 echo '</tr><tr>';                 continue;                 }             if ($x==20){                 echo '</tr>';                 }                }             function somelongassfunction(){                 return 'hello';                 }             function have_products($a){                 return $a<=20;                 }                ?>              </table> 

this code loops , dynamically adds table cells limit give represent database items. every 3 rows, adds either <tr></tr> or </tr> depending on whether loop continues or not. creates 3 column table. can't apply code script because long , complex script has lot of if statements , functions. there no way of doing without breaking code or having rewrite scratch on again.

is there anyway can append tr tags dynamically jquery , how go applying to?

the jquery approach loop through of tabs, , add them newly created tags, added html of table. roughly:

var thiscount=0; var currenttag="<tr />"; var table=$("table"); $("td").each(function ()  {     if(thiscount==2)         {              table.appendchild(currenttag);              thiscount=0;              currenttag="<tr />";         }      currenttag.appendchild(this); } 

( give idea, not intended formal jq answer. if wants edit works fully, feel free ).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -