Jump to content

insert using implode


Yohanne
Go to solution Solved by Yohanne,

Recommended Posts

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;
       } 

 image.png

Link to comment
Share on other sites

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
Share on other sites

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;
	} 
Edited by JaysonDotPH
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.