I am trying to display some data from a submitted form. I can get it to display, but need some help with the way it echos the data if multiple responses are available. Not to sure if I need to make a function or not, but this is what I have right now. if ($row['txtNotificationAgency1'] == "GLO") { echo "GLO "; } if ($row['txtNotificationAgency2'] == "TCEQ") { echo "TCEQ "; } if ($row['txtNotificationAgency3'] == "RRC") { echo "RRC "; } Code (markup): What I would like to happen is say if "GLO" & "RRC" the the output display GLO / RRC, but if only say "RRC" then output display RRC. I'm not very knowledgeable in PHP, but I think I need some kind of function but not sure how to go about it. Can anyone help?!?!?
$out = array(); if ($row['txtNotificationAgency1'] == "GLO") { $out[] = "GLO "; } if ($row['txtNotificationAgency2'] == "TCEQ") { $out[] = "TCEQ "; } if ($row['txtNotificationAgency3'] == "RRC") { $out[] = "RRC "; } echo implode(' / ', $out); PHP: Something like that should do it
You beat me to it JAY if ($row['txtNotificationAgency1'] == "GLO") $output[] = "GLO"; if ($row['txtNotificationAgency2'] == "TCEQ") $output[] = "TCEQ"; if ($row['txtNotificationAgency3'] == "RRC") $output[] = "RRC"; $str = implode(' / ',$output); PHP:
Worked perfectly, thanks again. Could be very useful with some other projects. After your replies I read about it on php.net and kinda understand it, but not totally. Sure I'll understand more as I use it more.
The $out[] assigns each of the items to the array $out, then the implode puts each of the texts into one string and separates them with the /
I kinda got that part. I think it lost me when it made arrays out of 3 different if statements, didn't know that could be done. Thats why I am liking PHP, every day I learn something new.