If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Create an option select from all rows of table as a single string variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-03-09, 08:20
Iowarth Iowarth is offline
Registered User
 
Join Date: Aug 2009
Posts: 5
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
Reply With Quote
  #2 (permalink)  
Old 08-03-09, 08:23
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
dump the text to a variable
insert that variable as required
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 08-03-09, 14:31
Iowarth Iowarth is offline
Registered User
 
Join Date: Aug 2009
Posts: 5
Yeap - that's what I want ..... but how?
Reply With Quote
  #4 (permalink)  
Old 08-03-09, 14:44
Iowarth Iowarth is offline
Registered User
 
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 14:48.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On