1

For every comma inside a certain MYSQL row,

I want to create x html elements, where x = number of commas inside a row.

So for example, if my mysql row looks like this:

dance, singing, drawing, acting,

That is 4 commas.

I want to create a html box (using a div) for every comma, and inside that box, show the hobby..

So like on the main.php page, show :

[ dance ]

[ singing ]

[ drawing ]

[ acting ]

How does one go about creating a certain number of html elements based on a certain number of commas in a mysql table, assuming that I will add more hobbies to the table?

BTW, I am using php as the server side languange.

Any help would be appreciated, thank you.

1 Answer 1

1

This is untested, so consider it psuedo-code. You may need to escape the square brackets. The other issue you could encounter is that there could be an empty div output at the very end. In that case, just check that $elem != ''.

$elements = explode(',', $mysql_data_column);
foreach($elements as $elem)
{
   echo "<div style=\"block\">[$elem]</div>";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.