Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within PHP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
PHP
codeigniter unable to insert multiple row data to database
gong tji
Ranch Hand
Posts: 97
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello everyone,
I had try to insert data using codeigniter like this :
my views :
<?php echo form_open('index.php/testadddiscount');?> $n = 1; foreach($disc as $exist) { echo " <input name=\"iddisc".$n."\" type=\"text\" value=\"".$iddisc."\" class=\"textbox\" /> <input name=\"dname".$n."\" value=\"".$discount_name."\" type=\"text\" /> "; $n++ } // end foreach <input type="submit" value="send" /> <?php echo form_close();?>
my models :
function discount() { $query = $this->db->get('discount'); $query = $query->result(); $n =1; foreach($query as $rows) { $data[$n] = array( 'iddiscount'=> $_POST['iddisc'.$n], 'discountname' => $_POST['dname'.$n], 'status' => 1 ); $this->db->insert('test',$data[$n]); $n++; } return $this->db->insert_id(); }
and finally this my controller :
function testadddiscount() { $this->test_model->discount(); }
please someone help me
Thanks
K. Tsang
Bartender
Posts: 3648
16
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you determine whether the model gets the correct number of records (your "$rows" variable)?
The discount function in the model clearly only return one insert ID rather than multiple IDs.
From the look of the foreach, you seem to be looping the data. This makes whatever returned is most likely the last row you inserted.
Is the foreach loop inserting correctly?
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
Muhammad Ali Rafique
Greenhorn
Posts: 1
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please use batch insert
insert_bactch method.
http://stackoverflow.com/questions/14946766/codeigniter-insert-multiple-records-without-cycle
https://www.codeigniter.com/user_guide/database/query_builder.html?highlight=active%20record#inserting-data
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Javascript and PHP
Insert into multiple tables PDO
problem in updating data
PHP Basics
\r\n db saving and echo issue
More...