1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Merge 3 arrays to insert in one row in db

Discussion in 'PHP' started by ausgezeichnete, May 7, 2009.

  1. #1
    i have those three arrays for example
    $num=array(1,2,3);
    $name=array('one','two','three');
    $letter=array('m','k','n');

    what i want is to loop through all of them and insert them like that:

    insert into mydb (field1,field2.field3) values(1,'one','m');
    ausge is online now Report Post Edit/Delete Message
     
    ausgezeichnete, May 7, 2009 IP
  2. mrmaf

    mrmaf Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yeah my Dear you can do this in php

    Let's look how to do this.

    $i=0;

    while($i<3)
    {
    $query="insert into yourtable values('$num[$i]','$name[$i]','$letter[$i]')";
    $result=mysql_query($query);
    $i=$i+1;
    }

    if($result)
    {
    echo "Records Successfully Entered";
    }
    else{
    echo mysql_error();
    }

    This code will do what you want.

    Happy Coding...!
     
    mrmaf, May 7, 2009 IP
  3. manzoD15

    manzoD15 Guest

    Messages:
    126
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the useful information. Very relevant.
     
    manzoD15, May 7, 2009 IP
  4. lambda1

    lambda1 Well-Known Member

    Messages:
    993
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    i really found it very useful.. thanks..
     
    lambda1, May 8, 2009 IP