This topic is locked

Adding Mulitple Same Items

4/18/2009 5:10:55 PM
PHPRunner General questions
N
nitro23456 author

I would like to add the same item many times, determined by a drop down box for quantity, when I click submit.
I would only want to type the information in once, but it be added say 10 times (or maybe 20 as selected by a drop down field) to the database when I click submit.
I have the ID field as primary key, but this isn't sufficient.
FOR EXAMPLE:

If i had the details of 10x tins of soup to add that were all the same, I want to type it once, but have a field named 'number' where it would fill in automatically... tin 1of10, tin 2of10, tin 3of10 etc
and also for anything else, like cake 1 of 5, cake 2 of 5 etc as determined by the drop down box.

J
Jane 4/20/2009

Hi,
you can check number field in the Before record added event on the Eventstab and add 10 records in this event.

N
nitro23456 author 4/25/2009

Hi
Thanks for the reply. Can you give me some more details on how to do this? How do I make this user-defined as well, where the number of duplicate records produced is chosen by the user using a 'drop down box' field.

J
Jane 4/27/2009

Hi,
you can create field in the database, then set up this field asLookup wizard on the "Edit as" settings dialog on the Visual Editor tab.

You can check selected value in the Before record added event and add required number of records in this event.

N
nitro23456 author 4/27/2009

I am still having trouble with this. Using version 5.0.
I have set up the drop down fields with options 1-50
If i then proceed to the 'events' tab and on 'add page' then 'before record added'
I don't know what to do there.... I have options for emailing, database and other........ none of which seem to offer this?

500464 4/27/2009

Hey,
try anything like that:

for($i=1;$i<=10;$i++)

{

mysql_query("Insert into xyz ('field1','field2','field3'...) VALUES ('".$i."','value2','valu3'...)");

}


please correct me if I Have undestood you wrong...
Regards
Daniel

N
nitro23456 author 4/27/2009

Hey,

try anything like that:

for($i=1;$i<=10;$i++)

{

mysql_query("Insert into xyz ('field1','field2','field3'...) VALUES ('".$i."','value2','valu3'...)");

}


please correct me if I Have undestood you wrong...
Regards
Daniel


I still don't understand.
The field that is a dropdown box with option 1-50 is {$NUMBER_RECEIVED_IN_BATCH_value} ...... so the user may receive 10 or 25 or whatever, and use this drop down box to say how many they have received. I want this number selected to be the number of records made (there are approximately 10 other fields it would need to replicate with it)
Could someone PLEASE tell me how to do this as my whole project depends on this.
Is it a 'custom code' on 'events' tab and on 'add page' then 'before record added'?

J
Jane 4/28/2009

Hi,
yes, it's a custom code.

Please see my sample below:

for($i=1;$i<=$values["NUMBER_RECEIVED_IN_BATCH"];$i++)

{

mysql_query("Insert into xyz ('field1','field2','field3'...) VALUES ('".$i."','value2','valu3'...)");

}

N
nitro23456 author 4/28/2009

Hi,

yes, it's a custom code.

Please see my sample below:


I presume I change 'xyz' to my table name? ......... and field1 field 2 etc to my field names? ....... what about values?
this is doing nothing:

for($i=1;$i<=$values["NUMBER_RECEIVED_IN_BATCH"];$i++)

{

mysql_query("Insert into MYTABLENAME ('field1','field2','field3','field4','field5','field6','field7','field8','field9','field10','field11','field12','field13','field14','field15','field16') VALUES ('".$i."','value2','value3','value4','value5','value6','value7','value8','value9','value10','value11','value12','value13','value14','value15','value16'");

}
return true;

J
Jane 4/28/2009

All entered values are stored in the $values array, I.e.

mysql_query("Insert into xyz ('field1','field2','field3'...) VALUES ('".$i."','".$values["field2"]."','".$values["field3"]."'...)");

N
nitro23456 author 4/28/2009

All entered values are stored in the $values array, I.e.



Thanks, so the correct code would be?:

for($i=1;$i<=$values["NUMBER_RECEIVED_IN_BATCH"];$i++)

{

mysql_query("Insert into MYTABLENAME ('field1','field2','field3','field4','field5','field6','field7','field8','field9','field10','field11','field12','field13','field14','field15','field16') VALUES ('".$i."','".$values["field2"]."','".$values["field3"]."','".$values["field4"]."','".$values["field5"]."','".$values["field6"]."','".$values["field7"]."','".$values["field8"]."','".$values["field9"]."','".$values["field10"]."','".$values["field11"]."','".$values["field12"]."','".$values["field13"]."','".$values["field14"]."','".$values["field15"]."','".$values["field16"]."')");

}
return true;


DO I need to change xyz to MYTABLENAME? and field1 field2 etc to the names of my actual fields?
field1 is my autoincrement field called 'ID' so I dont want this copied.

field2 is called 'SITE'
Can you please show me an example code that I can extend to all my feilds?
EDIT: I can't get this to work at all, I have tried the code as it is.... then after changing the xyx to mytablename....... then changing the field1 field2 to my field names etc etc It jsut adds the record once.
PLEASE HELP!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=40565&image=1&table=forumreplies' class='bbc_emoticon' alt=':blink:' />

J
Jane 4/29/2009

Hi,
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.