Hi,
I would like to have a list of values entered into a text area (seperated by return) that are stored in a mysql database. These values are then pulled out and placed into a list or menu. Possible?
Thanks in advance,
Text Area To Menu or List
Moderator: General Moderators
Yes. Here is the basic structure of the code you would want.
1. Query and get the values from the database
2. [php_man]explode[/php_man] the results by \n
3. Loop through the results and echo each value.
Example:
1. Query and get the values from the database
2. [php_man]explode[/php_man] the results by \n
3. Loop through the results and echo each value.
Example:
Code: Select all
<?php
$query = "SELECT values FROM tablename";
$result = mysql_query($query);
$valuelist = explode("\n", $result);
foreach ($valuelist as $key => $value) {
echo "$value<br>\n";
}
?>-
Subliminal
- Forum Commoner
- Posts: 40
- Joined: Thu Oct 23, 2003 8:12 pm
I've always wonder what exactly that means, but I do know it is the $result when you query the database. I forgot to add one important line, here is a fixed example:
Code: Select all
<?php
$query = "SELECT values FROM tablename";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result))
{
$valuelist = explode("\n", $r['values']); //change the word 'values' to whatever the column is called in the database
echo "<table border="1"><tr><th>Menu</th></tr>\n";
foreach ($valuelist as $key => $value)
{
echo "<tr><td>";
echo "$value<br>\n"; // for every value, another menu item is generated
echo "</tr></td>"; // so this is where you would change the menu code
}
echo "</table>";
}
?>