SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Passionate Web Developer Egyptechno's Avatar
    Join Date
    Jan 2004
    Location
    Dubai
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A complicated Problem !!

    ok,

    it's some difficult .. I hope one can get it !

    we have 2 rows in SQL database .. name and email .. both are text

    the customer will open a page .. and will see a big textarea ..

    and enter his information as :

    name1-name2[email2]-name3-name4-name5[email5]

    example :
    jhone-mikey[mm@mm.com]-nick-nikki[nikk@nn.com]

    I want to insert this data in the database .. as :
    name email
    jhone
    mikey mm@mm.com
    nick
    nikki nikk@nn.com

    of cours we will use explode to do that and for each ..

    but it's a little complicated because it's a douple !

    sending my greatest regards for who has the answer

  2. #2
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have two 'columns' in a db --- one (name) and one (email)??

    Why do you need to use a text area? Why don't you just use separate text fields?

    CUSTOMER 1:
    Name: [FIELD]
    eMail: [FIELD]

    CUSTOMER 2:
    Name: [FIELD]
    eMail: [FIELD]
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with KD; however I can see where there might be multiple names/emails where the number is dynamic. As I see it the major problem is not one of splitting the data into separate rows, rather one of controlling (actually the lack of controlling) how the user enters the data.

    IF (and thats a mighty big word) the users enters the data properly...

    the thought process.

    explode the data using the dash - as the separator. then explode each element using the bracket as the new separator.

    pusedo-code
    PHP Code:
    $text jhone-mikey[mm@mm.com]-nick-nikki[nikk@nn.com// get your textarea input

    $array1 explode("-"$text);
    // $array1[0] = jhone
    // $array1[1] = mikey[mm@mm.com]
    // $array1[2] = nick
    // $array1[3] = nikki[nikk@nn.com]
    // etc etc

    $count1 count($array1// count the elements in array1

    for ($i=0$i $count1$i ++) {
      if 
    the bracket is contained in $array1[$i]
        
    explode $array1[$iusing the bracket as separator into array2
          $name 
    $array2[0]
          
    $email $array2[1// use preg_replace to remove the brackets
      
    else
        
    $name $array1[$i]
        
    $email ""
      
    endif
      
    insert data in database
    endfor 

    Lite...

  4. #4
    Passionate Web Developer Egyptechno's Avatar
    Join Date
    Jan 2004
    Location
    Dubai
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    KD,

    thanks for your reply first ..
    the adminstrator will input abput 40 name with emails ( maybe without emails )
    so, If I did as u said .. it will be very hard ^_^


    liter :
    thanks you too, I had the idea .. but I didn't know how to make it ..
    but Now thanks to my god, I did it ..
    and that's :
    PHP Code:
    $all "alahli[www.com]-zamalik-wa7dat[www.e.com]";

    $a explode('-',$all);

    $v = array();
    //
    foreach($a as $val){
        
    $v explode('[',$val);
        
    $v[1] = str_replace('[','',$v[1]);
        
    $v[1] = str_replace(']','',$v[1]);
        echo 
    "Name: $v[0] - Site: $v[1]<br>";
        
    $ins = @mysql_query("INSERT INTO allteams (at_name,at_url)
                            VALUES ('
    $v[0]','$v[1]')");
        if(!
    $ins){
            echo 
    "<br>[Error] in $v[0]:$v[1]<br>";
        }


  5. #5
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you got it!!
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •