Forum Moderators: coopster
so lets say that the value i pull from the db is, $ethnicity with shows up as 4,
how do I get the correct entry from this function,
$prof[ethnicity][0] = "I prefer not to say";
$prof[ethnicity][1] = "African";
$prof[ethnicity][2] = "African American";
$prof[ethnicity][3] = "Asian";
$prof[ethnicity][4] = "Caucasian";
$prof[ethnicity][5] = "East Indian";
$prof[ethnicity][6] = "Hispanic";
$prof[ethnicity][7] = "Indian";
$prof[ethnicity][8] = "Latino";
$prof[ethnicity][9] = "Mediterranean";
$prof[ethnicity][10] = "Middle Eastern";
$prof[ethnicity][11] = "Mixed";
I thought i would be something like:
$ShowEthnicity= $prof[ethnicity]['.$ethnicity.'];
but it's not working, and i'm not getting any errors,,
can someone please show me what i'm doing wrong here?
thanks in advance for your time!
-Ken
my code:
<?php
$prof[ethnicity][0] = "I prefer not to say";
$prof[ethnicity][1] = "African";
$prof[ethnicity][2] = "African American";
$prof[ethnicity][3] = "Asian";
$prof[ethnicity][4] = "Caucasian";
$prof[ethnicity][5] = "East Indian";
$prof[ethnicity][6] = "Hispanic";
$prof[ethnicity][7] = "Indian";
$prof[ethnicity][8] = "Latino";
$prof[ethnicity][9] = "Mediterranean";
$prof[ethnicity][10] = "Middle Eastern";
$prof[ethnicity][11] = "Mixed";
echo $prof[ethnicity][4];
?>
I made the value static, as 4.
this does give me the correct result, but also gives me some errors:
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 3
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 4
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 5
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 6
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 7
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 8
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 9
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 10
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 11
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 12
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 13
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 14
Notice: Use of undefined constant ethnicity - assumed 'ethnicity' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 17
Caucasian
the correct value appears at the bottom of the errors on the page.
what am i doing wrong here, that I get the correct value but still errors?
thanks again for your time!
-Ken
$prof[ethnicity][0] = "I prefer not to say";
$prof[ethnicity][1] = "African";
$prof[ethnicity][2] = "African American";
Try this:
$prof['ethnicity'][0] = "I prefer not to say";
$prof['ethnicity'][1] = "African";
$prof['ethnicity'][2] = "African American";
Then you should be able to call it like this:
$ShowEthnicity = $prof['ethnicity'][$ethnicity];
hope that helps ...
-sned
will this same script work with letters insted of numbers?
like
$prof['relationship'][act] = "Activity Partner";
$prof['relationship'][cas] = "Casual";
$prof['relationship'][fri] = "Friendship";
$prof['relationship'][mar] = "Marriage";
$prof['relationship'][rel] = "Relationship";
$prof['relationship'][rom] = "Romance";
$prof['relationship'][tra] = "Travel Partner";
also how do i parse a coma seperated string to get the right values.
example:
I would pull:
act,cas,fri,mar,rel,rom,tra
from my data base.
how do i then read into this string, pull the data from the array above. and then have it show up as:
Activity Partner, Casual, Friendship, and so on?
thanks again for all you help!
-Ken
$prof['relationship'][act] = "Activity Partner";
$prof['relationship'][cas] = "Casual";
should be:
$prof['relationship']['act'] = "Activity Partner";
$prof['relationship']['cas'] = "Casual";
If your database returns a string like "act,cas,fri,mar,rel,rom,tra"
You can use the explode [us4.php.net] function: $some_array = explode(',', $database_result);
Then, to pull the data from the $prof['relationship'] array, you would do something like:
foreach($some_array as $id=>$value){
echo $prof['relationship'][$id];
}
That's one of the ways it could be done ....
-sned