1 Reply Latest reply on May 2, 2006 8:22 PM by Dan Bracuk

    CFLOOP and OPTION selected

      Hi, can anyone help.

      Here is the basic idea, working on a shop which displays 9 tshirts, 3x3. Want the admin of the shop to be able to select which 9 shirts will be shown to the user.

      I have a loop which puts all the items in order, and i know I could use individual cfqueries for every cell in the table, but thought Id try something better.

      It seems to put 'selected' at most of the options in each drop down menu! not just the one currently chosen by the shop person the last time!

      I want the loop to populate the drop down menus, and if the item is the current selection, then it is selected. not the others.

      Can someone help.

      This is the admin, very basic! The site

      Many Thanks


      <cfif IsDefined("form.submit")>
      <cfset loop = 1>
      <cfloop index="i" from="1" to="9">
      <cfset images = 'form.image' & #loop#>

      <cfquery name="idshirt" ...
      SELECT ShirtID, title, image
      FROM proart
      WHERE image = "#Evaluate("form.image" & loop)#"

      <cfquery name="update" ...
      UPDATE proartmenu
      SET image = "#idshirt.image#", ShirtID = "#idshirt.ShirtID#", title = "#idshirt.title#"
      WHERE PicID = #loop#;
      <cfset loop = loop + 1>

      <cfquery name="shirts" ...
      select * from proart;

      <CFSET max_seq = #shirts.recordcount#>
      <CFSET max_rows = INT((#max_seq# +2)/3)>
      <CFSET x = 0>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns=" http://www.w3.org/1999/xhtml">
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Untitled Document</title>
      <style type="text/css">
      .selected { background-color:#CCCCCC;}

      <body><form id="form" name="form" method="post" action="pop.cfm">

      <table width="90%" height="90" border="1" align="center">
      <CFLOOP INDEX="seq_no" FROM="1" TO="#max_rows#">
      <CFLOOP INDEX="sequence" FROM="1" TO="3">
      <CFSET x = x + 1>

      <select name="image<cfoutput>#x#</cfoutput>">
      <cfoutput query="shirts">
      <CFQUERY NAME="themenu" ...
      SELECT * FROM proartmenu
      WHERE PicID = #x#;

      <CFQUERY NAME="theshirts" ...">
      SELECT * FROM proart;

      <cfif themenu.image IS NOT theshirts.image>
      <option value="#Image#">#Title#</option>
      <option value="#Image#" selected="selected" class="selected">#Title#</option>



      <input name="submit" type="submit" />


        • 1. Re: CFLOOP and OPTION selected
          Dan Bracuk Level 5
          So your goal is to pre-select options in a multi-select? Here is the general idea.

          Run two cfqueries, q1 and q2. q1 selects all available items and q2 selects the ones you want to preselect. Let's call the fields id and name.

          <select multiple etc>
          <cfoutput query = "q1">
          <option name = "id" value = "#id#"
          <cfif ListFind(ValueList(q2.id), id)>"selected"</cfif>