How to join some data values become string

hello :slight_smile:
i’m so sorry because my english is horrible :smiley:
i have trouble when i was create my system (classification with decision tree in php programming)
i want to join some data values from my database(mysql) become string in php
this is my database

[table]
[tr]
[td]id[/td]
[td]id_rule[/td]
[td]attribute[/td]
[td]attribute_value[/td]
[td]decision[/td]
[/tr]
[tr]
[td]1[/td]
[td]4[/td]
[td]gill_size[/td]
[td]narrow[/td]
[td]edible[/td]
[/tr]
[tr]
[td]2[/td]
[td]4[/td]
[td]ring_type[/td]
[td]evanescent[/td]
[td]edible[/td]
[/tr]
[tr]
[td]3[/td]
[td]4[/td]
[td]cap_surface[/td]
[td]fibrous[/td]
[td]edible[/td]
[/tr]
[/table]

so i want to join the data values in attribute,attribute value and decision order by id rule
example : the data in 2nd row, 3rd row and 4th row have same id rule (id_rule = 4)
so i wanna create like this "if [gill_size = narrow] and [ring_type = evanescence] and [cap_surface=fibrous] then [edible]
so any word “if and then”
how to create like that?
please help me :frowning:
and sorry for my horrible english language

The logic is wrong. Your “if statements” make sense, but not according the database structure you’ve created.

id id_rule gill_size ring_type cap_surface decision
1 4 narrow evanescent fibrous edible
2 4 broad blah smooth edible
3 4 medium blahlah marbled edible

I really don’t know what kind of values should go under those columns, but that should give you a better idea.

Your SELECT query should look something like this:
[php]$query = “SELECT * FROM id, id_rule, gill_size, ring_type, cap_surface, decision WHERE id_rule=‘4’”
$result = mysql_query($query);
if($result === FALSE) {die(mysql_error());}
while($row = mysql_fetch_array($result)) {
$id = $row[‘id’];
$id_rule = $row[‘id_rule’];
$gill_size = $row[‘gill_size’];
$ring_type = $row[‘ring_type’];
$cap_surface = $row[‘cap_surface’];
[/php]

Plug those values into your HTML.

Place your if statements where appropriate:
[php]if($gill_size == “narrow”) {
echo ‘The gill size is narrow.’;
}[/php]

Check if $decision pulls a value from the DB
[php]if(isset($decision)) {
echo ‘A value for decision exists’;
} else {
echo ‘A value for decision does NOT exist’;
}
[/php]

That should be enough to get you started.

PS: What is the purpose of “id_rule”?

the purpose of id_rule is arrange the some data values become one sentence that have the same id_rule
for your info, i create classification system with decision tree and that’s why i must arrange the some data values become one rule for my decision tree
And why [gill_size = narrow] and [ring_type = evanescence] and [cap_surface=fibrous] become one sentence because that some data values have same id rule
i’ll give u the other examples :

[table]
[tr]
[td]id[/td]
[td]id_rule[/td]
[td]attribute[/td]
[td]attribute_value[/td]
[td]decision[/td]
[/tr]
[tr]
[td]1[/td]
[td]5[/td]
[td]gill_size[/td]
[td]narrow[/td]
[td]edible[/td]
[/tr]
[tr]
[td]2[/td]
[td]5[/td]
[td]ring_type[/td]
[td]pendant[/td]
[td]edible[/td]
[/tr]
[tr]
[td]3[/td]
[td]6[/td]
[td]cap_surface[/td]
[td]fibrous[/td]
[td]poisonous[/td]
[/tr]
[tr]
[td]4[/td]
[td]6[/td]
[td]cap_shape[/td]
[td]flat[/td]
[td]poisonous[/td]
[/tr]
[tr]
[td]5[/td]
[td]6[/td]
[td]cap_color[/td]
[td]white[/td]
[td]poisonous[/td]
[/tr]
[/table]

in the above example that should be “if [gill_size=narrow] and [ring_type=pendant] then edible” because gill_size=narrow and ring_type=pendant have the same id_rule(5)
or the other example “if [cap_surface=fibrous] and [cap_shape=flat] and [cap_color=white] then poisonous” because that data have the same id_rule(6)
when i want to display the output i wanna add word “if” “and” “then” so it would be like the above example

how to create that?
Am i should use the function “implode” and array in php?

Sponsor our Newsletter | Privacy Policy | Terms of Service