Queries in form

Hey, probably a long shot, but I have a form, and I would like to put queries in the form.

<SELECT NAME=TOPICS>
<OPTION>Post 1</OPTION>
<OPTION>Post 2</OPTION>
<OPTION>Post 3</OPTION>
</SELECT>

Is there anyway, I can use “SELECT topicid FROM topics” and have the outputs in the options, replacing post1, post2, post3.

Also, I need to be able to use the topicid as the value for each option. EG:

<SELECT NAME=TOPICS>
<OPTION VALUE=111>111</OPTION>
<OPTION VALUE=222>222</OPTION>
<OPTION VALUE=333>333</OPTION>
</SELECT>

If all you need are the ids and names from one table your query is fine. The results can be returned as an associative or numeric keyed array eg.
$result[0][‘id’] = 111;
$result[0][0] = 111;

Using associative arrays is more verbose, but you’re less likely to forget what is what.

Once you get the array you can loop through it using the values to populate your select options eg.

echo "<select …
foreach ( $results as $result )
{
echo “<option …” . $result[‘id’] . “>” . $result[‘name’] . …
}
echo “</select>”;

did you flag it?

but you’ve already got 100% of the mysql portion of this…

yup, I flagged it.

But it is mainly mysql, because I need to some how output the mysql into the html.

this is now a php question.

can somebody move it across, please.

bazz

I dont quite understand… This is a more detailed example of what I need.

SELECT topic_id, topic_name FROM topics

<SELECT NAME=TOPICS>
<OPTION VALUE=Topic_id>Topic Name</OPTION>
<OPTION VALUE=Topic_id>Topic Name</OPTION>
<OPTION VALUE=Topic_id>Topic Name</OPTION>
</SELECT>

And I need that to output all the topic names that match my mysql query


select topic_id, topic
from topics

then run it in a loop in your server-side language.

bazz

Ah right, I got ya :slight_smile: Thanks

The query is MySQL. How you convert the results to html output is processed by php, perl, whatever language you use.

bazz