PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
harkly
Forum Newbie
Posts: 6 Joined: Sat Apr 18, 2009 10:00 pm
Post
by harkly » Fri Jan 15, 2010 10:04 pm
I have this code that prints out all ethinics a person chooses, I also what it to print out any that was input by the user but I can't figure out how to get it to work - just this part isn't working
Code: Select all
if ($r['othr_Ethn']) $string .= "$othr_Ethn_txt";
the rest works fine.
Here is the full code-
Code: Select all
$sql = mysql_query("SELECT * FROM ethn WHERE userId = 'kelly'");
while($r = mysql_fetch_array($sql)) {
$string = "";
if ($r['asian']) $string .= "Asian, ";
if ($r['black']) $string .= "Black/African, ";
if ($r['east_indian']) $string .= "East Indian, ";
if ($r['mid_eastern']) $string .= "Middle Eastern, ";
if ($r['hispanic']) $string .= "Latino/Hispanic, ";
if ($r['native']) $string .= "Native American, ";
if ($r['pac_haw']) $string .= "Pacific Islander/Hawaiian, ";
if ($r['white_eu']) $string .= "White/Caucasian, ";
if ($r['othr_Ethn']) $string .= "$othr_Ethn_txt";
$string = rtrim($string, ", ");
echo " $string \n";
}
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Sat Jan 16, 2010 1:23 am
Remove the brackets from the variable, so make this:
if ($r['othr_Ethn']) $string .= "$othr_Ethn_txt";
like this:
if ($r['othr_Ethn']) $string .= $othr_Ethn_txt;
harkly
Forum Newbie
Posts: 6 Joined: Sat Apr 18, 2009 10:00 pm
Post
by harkly » Sat Jan 16, 2010 9:48 am
Thanks
I got it to work with this
Code: Select all
if ($r['othr_Ethn']) $string .= ($r['othr_Ethn_txt']);