www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: multiple select box values

  1. #1
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898

    multiple select box values

    I have a multiple select box with contact names and phone numbers. When you select a name that has "Investors" in front of it, I want it to display all the Names and phone numbers, but only show the word Investors once. For example, I want it to look like this:

    Invesors: Name Phone Number, Name2, Phone Number 2

    Here is the code I am using to seperate the value by a comma:

    <? foreach($contacts as $value) {
    list ($id, $info) = split (",", $value);
    echo "<input type=hidden name=contacts[] value=$id,$info>\n";
    }?>

    Then here is the code I am using to display the data:

    <?
    echo "Contacts:";
    foreach($contacts as $value) {
    list ($id, $info) = split (",", $value);
    $info = str_replace("~", "&nbsp;", $info);
    $inv = substr("$info", 0, 9);
    //while ($inv == "Investors") {
    // echo "<p>" . $info . ",&nbsp;";
    //}
    if ($inv == "Investors") {
    echo "<p>" . $info . "&nbsp;or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
    } else {
    echo "<p>" . $info . "</p>";
    }
    }
    ?>

    But this gives me the following result:

    Investors: Name Phone Number
    Investors: Name2 Phone Number

    Any help would be greatly appreciated

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    What does $contacts look like? If it is the contents of a file, post what the file looks like.

  3. #3
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    $contacts is an array that looks like this:

    Contacts:Array ( [0] => 1,Investors:~Jason~Roscoe~717-761-2633 [1] => 5,Investors:~Doug~Silvis~717-761-2633 [2] => 2,Media:~Jason~Kasper~717-761-2633 )

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Not the cleanest, but I would read/write the file differently, which would mean we could do this differently... Anyway, with what you've got:

    PHP Code:
    <?PHP

    $x 
    0;

    echo 
    "Contacts:"
    foreach(
    $contacts as $value) { 
        list (
    $id$info) = split (","$value); 
        
    $info str_replace("~"" "$info); 
        
    $invinfo substr($info11, -1);
        
    $inv substr("$info"09); 
        if (
    $inv == "Investors") {
            if (
    $x == 0) { 
                echo 
    "<p>Investors: " $invinfo " or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>"
                
    $x 1;
            }
            else {
                echo 
    "<p>" $invinfo " or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>"
            }
        } 
        else { 
            echo 
    "<p>" $info "</p>"
        } 


    ?>

  5. #5
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    Ok, we're close. This is what the page looks like now:

    Investors: Jason Roscoe 777-777-263 or investor@riteaid.com

    Doug Silvis 777-777-263 or investor@riteaid.com

    Media: Jason Kasper 777-777-2633

    But what I want it to look like is:

    Investors: Jason Roscoe 777-777-2633, Doug Silvis 777-777-2633 or investor@riteaid.com

    Media: Jason Kasper 777-777-2633

    Also, it is cutting off the last number in the phone number??

    P.S. - I got the phone number to show all numbers by doing this:

    $invinfo = substr($info, 11);
    Last edited by jrthor2; 06-10-2003 at 12:21 PM.

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    PHP Code:
    if ($inv == "Investors") {
        if (
    $x == 0) { 
            echo 
    "<p>Investors: " $invinfo " or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a>,"
            
    $x 1;
        }
        else {
            echo 
    " " $invinfo " or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a>,"
        }

    else { 

  7. #7
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    Ok, now I have this:

    Investors: Jason Roscoe 777-777-2633 or investor@riteaid.com, Doug Silvis 777-777-2633 or investor@riteaid.com,

    But, I want the "or investor@riteaid.com" to only show up at the end of that line like this:

    Investors: Jason Roscoe 777-777-2633, Doug Silvis 777-777-2633 or investor@riteaid.com,

    Thanks

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Is it possible for you to re-work the way the file looks? (I'm assumbing this data is being pulled from a file) It would be much easier if you were able to split it up differently....

  9. #9
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    Yes, it is possible. the select box is being pulled from a database. The info I am showing is just being passed from the form to this page. I will try anything right now.

    Thanks

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Actually... let's go the easy way, and just keep what you've already got. Try this:

    PHP Code:
    <?PHP

    $invvals 
    "";
    $infovals "";
    $contacts file("array.txt");

    echo 
    "Contacts:"
    foreach(
    $contacts as $value) { 
        list (
    $id$info) = split (","$value); 
        
    $info str_replace("~"" "$info); 
        
    $invinfo substr($info11, -1);
        
    $inv substr("$info"09); 
        if (
    $inv == "Investors") {
            
    $invvals .= $invinfo." "
        } 
        else { 
            
    $infovals .= $info
        } 


    echo 
    "<p>Investors: $invvals <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
    echo 
    "<p>$infovals <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";

    ?>

  11. #11
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    Actuall, I had to modify it a little, but it looks to be working. here is what I used:

    <?PHP

    $invvals = "";
    $infovals = "";

    echo "Contacts:";
    foreach($contacts as $value) {
    list ($id, $info) = split (",", $value);
    $info = str_replace("~", " ", $info);
    $invinfo = substr($info, 11);
    $inv = substr("$info", 0, 9);
    if ($inv == "Investors") {
    $invvals .= $invinfo.", ";
    }
    else {
    $infovals .= $info;
    }
    }

    echo "<p>Investors: $invvals or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
    echo "<p>$infovals </p>";

    ?>

    Although, is it possible to not show the comma after the last person listed as an investor??

  12. #12
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Add this right after your foreach loop (before the echo's):

    PHP Code:
    $invvals substr($invvals0, -2); 

  13. #13
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    YEEEEEEEHAWWWW, it's finally working the way I need it to. Thanks so much. Now I have another issue. After putting this info away into a database, I need to retrieve it and display it the same way. Here is my code now, but it lists the investors in a new row:

    <?
    $sql="SELECT EVT.ITEM_NBR, EVT.TITLE_TXT,
    EVT.BODY_TXT, REF.ID, INF.FIRST_NME, INF.LAST_NME, INF.PHONE_NBR,
    INF.DEPARTMENT
    FROM SYSADM.INDYH_DYNCONTENT_HTML EVT,
    SYSADM.INCOR_CONTACT_REF REF,
    SYSADM.INCOI_CONTACT_INFO INF
    WHERE EVT.ITEM_NBR = $item_nbr
    AND EVT.ITEM_NBR = REF.ITEM_NBR
    AND REF.ID = INF.ID
    ORDER BY DEPARTMENT, INF.LAST_NME";
    $D->my_sel($sql);
    //print $sql;

    if ($D->numrows > 0) {
    echo "<p>Contacts:</p>";

    for($i=0; $i< $D->numrows; $i++) {
    $first_nme=$D->results["FIRST_NME"][$i];
    $last_nme=$D->results["LAST_NME"][$i];
    $phone_nbr=$D->results["PHONE_NBR"][$i];
    $department=$D->results["DEPARTMENT"][$i];
    if ($department == "Investors") {
    if ($first_nme == "0") {
    $contact_info = "<p>" . $department . ":&nbsp;" . $phone_nbr . "&nbsp;or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
    } else {
    $contact_info = "<p>" . $department . ":&nbsp;" . $first_nme . "&nbsp;" . $last_nme . "&nbsp;" . $phone_nbr . "&nbsp;or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
    }
    } else {
    $contact_info = "<p>" . $department . ":&nbsp;" . $first_nme . "&nbsp;" . $last_nme . "&nbsp;" . $phone_nbr;
    }
    }
    ?>

    Thanks for all your help!!!

  14. #14
    Join Date
    Jan 2003
    Location
    PA
    Posts
    1,898
    Can anyone please help?

  15. #15
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Could you explain your problem/question better?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles