0

I have dynamically created labels which has id as "label+i". Those labels get their text from again dynamically created textboxes with id's as ""text"+i". I get total numbers of textbox from user. What I'm trying is if I get 12 labels I want to have 3 row in total. All rows has 4 columns in db. Max number of label will be 28 or 32 so there will not be a hundred of labels.

For example if I have

 label1, label2, label3, label4,label5,label6,label7,label8

then first row of database will be

    col1=label1
    col2=label2
    col3=label3
    col4=label4

and second row will be

    col1=label5
    col2=label6
    col3=label7
    col4=label8

Since I don't know how to separate rows in a single query execution I couldn't think of a good algorithm. I need your help guys :)

thanks in advance.

chiastic-security
  • 20,430
  • 4
  • 39
  • 67
Afbyk
  • 101
  • 2
  • 7
  • 1
    If you are only talking about a few rows, why do you care if you have to do it over 7 or 8 queries, I doubt there would be a performance gain by using some kind of bulk insert technique for 7 or 8 rows. – Ben Robinson Sep 11 '14 at 09:28
  • See this question for inserting multiple rows in one query, http://stackoverflow.com/questions/6889065/inserting-multiple-rows-in-mysql – Ben Robinson Sep 11 '14 at 09:30

1 Answers1

0

you can do itsimple but hopefully will give you an idea how to do it.

for (int i=1;i<=NumOfLabels;i++){

if (i%4==0)
{
insert  into yourTable values( labels[i-4],labels[i-3],labels[i-2],labels[i-1]);
}

}
QuakeCore
  • 1,886
  • 2
  • 15
  • 33