Click to See Complete Forum and Search --> : multiple select box values
jrthor2
06-10-2003, 10:39 AM
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.
jrthor2
06-10-2003, 10:47 AM
$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
$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>";
}
}
?>
jrthor2
06-10-2003, 11:17 AM
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);
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 {
jrthor2
06-10-2003, 11:29 AM
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....
jrthor2
06-10-2003, 11:48 AM
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
$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>";
?>
jrthor2
06-10-2003, 12:33 PM
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):
$invvals = substr($invvals, 0, -2);
jrthor2
06-10-2003, 12:51 PM
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!!!
jrthor2
06-11-2003, 07:37 AM
Can anyone please help?
Could you explain your problem/question better?
jrthor2
06-11-2003, 07:47 AM
It's pretty much like what we worked on yesterday. I am selecting content from a database and need to display it the same way we did yesterday:
Investors: Name Phone Number, Name2 Phone Number2, etc.
This is how I am getting the data from the database:
$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];
And right now, it displays each row individually like:
Investors: Name Phone Number
Investors: Name2 Phone Number2
The code looks like this right now when displaying:
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;
}
?>
<font face="Arial, Helvetica, sans-serif">
<?=$contact_info?>
<?}
}?>
Then it will be close to what we did yesterday. This, perhaps?
$contact_info = "";
$contact_info2 = "";
if ($department == "Investors") {
if ($first_nme == "0") {
$contact_info .= $department . ": " . $phone_nbr;
}
else {
$contact_info .= $department . ": " . $first_nme . " " . $last_nme . " " . $phone_nbr;
}
}
else {
$contact_info2 .= $department . ": " . $first_nme . " " . $last_nme . " " . $phone_nbr;
}
echo "<p>$contact_info <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
echo "<p>$contact_info2 <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
jrthor2
06-11-2003, 08:18 AM
This code:
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];
$contact_info = "";
$contact_info2 = "";
if ($department == "Investors") {
if ($first_nme == "0") {
$contact_info .= $department . ": " . $phone_nbr;
}
else {
$contact_info .= $department . ": " . $first_nme . " " . $last_nme . " " . $phone_nbr;
}
}
else {
$contact_info2 .= $department . ": " . $first_nme . " " . $last_nme . " " . $phone_nbr;
}
echo "<p>$contact_info <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
echo "<p>$contact_info2</p>";
}
}
Gives me this:
Investors: John Standley 777-777-8857 investor@riteaid.com
Investors: Kevin Twomey 777-777-6540 investor@riteaid.com
investor@riteaid.com
Media: Karen Rugen 777-777-7766
What does this give you:
$contact_info = "";
$contact_info2 = "";
if ($department == "Investors") {
if ($first_nme == "0") {
$contact_info .= $phone_nbr;
}
else {
$contact_info .= $first_nme . " " . $last_nme . " " . $phone_nbr;
}
}
else {
$contact_info2 .= $first_nme . " " . $last_nme . " " . $phone_nbr;
}
echo "<p>Investors: $contact_info <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
echo "<p>Media: $contact_info2 <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
Make sure the echo statements are outside of any of your loops.
jrthor2
06-11-2003, 08:50 AM
I get this;
Investors: investor@riteaid.com
Media: Karen Rugen 777-777-7766
Using this code:
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];
$contact_info = "";
$contact_info2 = "";
if ($department == "Investors") {
if ($first_nme == "0") {
$contact_info .= $phone_nbr;
}
else {
$contact_info .= $first_nme . " " . $last_nme . " " . $phone_nbr;
}
}
else {
$contact_info2 .= $first_nme . " " . $last_nme . " " . $phone_nbr;
}
} //end for loop
} //end If $D->numrows > 0 loop
echo "<p>Investors: $contact_info <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
echo "<p>Media: $contact_info2</p>";
Try this one out... :)
$contact_info = "";
$contact_info2 = "";
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 .= $phone_nbr;
}
else {
$contact_info .= $first_nme . " " . $last_nme . " " . $phone_nbr;
}
}
else {
$contact_info2 .= $first_nme . " " . $last_nme . " " . $phone_nbr;
}
} //end for loop
} //end If $D->numrows > 0 loop
echo "<p>Investors: $contact_info <a href=mailto:investor@riteaid.com>investor@riteaid.com</a></p>";
echo "<p>Media: $contact_info2</p>";
jrthor2
06-11-2003, 09:04 AM
Yep, thanks a ton!!!!!!! :D