Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    5

    Unanswered: Create an option select from all rows of table as a single string variable

    Many apologies - I posted this in the MySQL forum and got gently told off. Thus re-posted here.

    I have a page which includes numerous images generated from a MySQL table each with its own form/drop-down box. The values in the drop down box are identical in all cases and limited in number - maximum 10.
    It is very easy to create a query to create the drop down box within the Select i.e.
    while($Row=mysql_fetch_array($Result))
    {
    print ("<option value='$Row[id]'>$Row[size] - $Row[price]</option>\n");
    }
    This produces for example:-
    <option value='1'>6ins x 4ins - 5.50</option>
    <option value='2'>8ins x 5ins - 7.50</option>

    But, I don't want to repeat this query with every picture for obvious reasons.
    So, how can I run the query just once on the page and load the entire output into a single string to use within each Select?
    example required result:-
    $optionstr="<option value='1'>6ins x 4ins - 5.50</option><option value='2'>8ins x 5ins - 7.50</option>";
    I am sure there is a simple solution which is evading my simple brain!
    Assistance appreciated.
    Chris

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    dump the text to a variable
    insert that variable as required
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Aug 2009
    Posts
    5
    Yeap - that's what I want ..... but how?

  4. #4
    Join Date
    Aug 2009
    Posts
    5
    Further to the above I presume you mean something like:-
    while($Row=mysql_fetch_array($Result))
    {
    $optionstr="<option value='$Row[id]'>$Row[size] - &#163;$Row[price]</option>";
    print("$optionstr\n");
    }
    This certainly generates the complete string but when I put the variable within the select, eg:-
    print("<select name='Select2' size='1' align='middle' style='font-size: xx-small;'>\n");
    print("$optionstr\n");
    print("</select><span class='body_text'>&nbsp;&nbsp;&nbsp;&nbsp;\n");
    the result shows only the last option (8 x 5 in my previous example)
    Many thanks
    Chris
    Last edited by Iowarth; 08-03-09 at 15:48.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •