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("~", " ", $info);
$inv = substr("$info", 0, 9);
//while ($inv == "Investors") {
// echo "<p>" . $info . ", ";
//}
if ($inv == "Investors") {
echo "<p>" . $info . " 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
What does $contacts look like? If it is the contents of a file, post what the file looks like.
$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 )
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 ( $info , 11 , - 1 );
$inv = substr ( " $info " , 0 , 9 );
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>" ;
}
}
?>
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 11:21 AM .
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 {
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
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....
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
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 ( $info , 11 , - 1 );
$inv = substr ( " $info " , 0 , 9 );
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>" ;
?>
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??
Add this right after your foreach loop (before the echo's):
PHP Code:
$invvals = substr ( $invvals , 0 , - 2 );
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 . ": " . $phone_nbr . " or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
} else {
$contact_info = "<p>" . $department . ": " . $first_nme . " " . $last_nme . " " . $phone_nbr . " or <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
}
} else {
$contact_info = "<p>" . $department . ": " . $first_nme . " " . $last_nme . " " . $phone_nbr;
}
}
?>
Thanks for all your help!!!
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
Forum Rules
Bookmarks