Page 1 of 1

data not printing out

Posted: Fri Jan 15, 2010 10:04 pm
by harkly
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";
 
}

Re: data not printing out

Posted: Sat Jan 16, 2010 1:23 am
by klevis miho
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;

Re: data not printing out

Posted: Sat Jan 16, 2010 9:48 am
by harkly
Thanks

I got it to work with this

Code: Select all

if ($r['othr_Ethn']) $string .= ($r['othr_Ethn_txt']);