Yohanne Posted April 3, 2014 Share Posted April 3, 2014 Hi coders, getting hard to insert, according to the image below. public function model_newtss($branch,$tssdate,$tss) { if($tss) { foreach($tss as $tss_s) { $tsss[] = $tss_s; } } $_implode = "('".implode("'),('",$tsss)."')"; $insert_tss = mysql_query("INSERT INTO code_tss(branch_id,tss_date,tss_trans_num) VALUES '$branch','$tssdate','$_implode'"); return $insert_tss; } Link to comment https://forums.phpfreaks.com/topic/287483-insert-using-implode/ Share on other sites More sharing options...
trq Posted April 3, 2014 Share Posted April 3, 2014 What? Link to comment https://forums.phpfreaks.com/topic/287483-insert-using-implode/#findComment-1474767 Share on other sites More sharing options...
Yohanne Posted April 3, 2014 Author Share Posted April 3, 2014 In image above "BRANCH" and "DATE" is not an array while "TSS #" is an array. BRANCH : <input type = "text" name = "branch" value = ""> DATE : <input type = "text" name = "date" value = ""> TSS NUMBER : <input type = "text" name = "tss[]" value = ""> //this line is, its up to a user how many input he/she want to add and defending on tss number. and now i am getting difficulties, how to insert together array/implode and none array or base on image above. Link to comment https://forums.phpfreaks.com/topic/287483-insert-using-implode/#findComment-1474770 Share on other sites More sharing options...
mac_gyver Posted April 3, 2014 Share Posted April 3, 2014 the sql syntax of your INSERT query is incorrect. you should be forming the sql query statement in a php variable so that you can echo it to see exactly what sql query statement is. Link to comment https://forums.phpfreaks.com/topic/287483-insert-using-implode/#findComment-1474774 Share on other sites More sharing options...
Yohanne Posted April 4, 2014 Author Share Posted April 4, 2014 thanks.. and now i change the scenario and im going explore something and it is not working well and please please let help me to correct this line of codes and i know it is possible. BRANCH : <input type = "text" name = "branch[]" value = ""> DATE : <input type = "text" name = "tssdate[]" value = ""> TSS NUMBER : <input type = "text" name = "tss[]" value = ""> USER : <input type = "text" name = "username[]" value = ""> public function model_newtss($branch,$tssdate,$tss,$username) { if($this->model_newtss) { foreach($this->model_newtss as $tss_s) { $tsss[] = $tss_s; } } $_implode = "('".implode("'),('",$tsss)."')"; $insert_tss = mysql_query("INSERT INTO code_tss(branch_id,tss_date,tss_trans_num,empid) VALUES ".$_implode.""); return $insert_tss; } Link to comment https://forums.phpfreaks.com/topic/287483-insert-using-implode/#findComment-1474915 Share on other sites More sharing options...
Yohanne Posted April 15, 2014 Author Share Posted April 15, 2014 Hi coders, Any help.. Link to comment https://forums.phpfreaks.com/topic/287483-insert-using-implode/#findComment-1476161 Share on other sites More sharing options...
Yohanne Posted April 15, 2014 Author Share Posted April 15, 2014 problem solve using for loop Link to comment https://forums.phpfreaks.com/topic/287483-insert-using-implode/#findComment-1476164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.