Link to home
Start Free TrialLog in
Avatar of jriver12
jriver12

asked on

Help with dynamic page layout.

I don't even know if this is possible.

I am trying to have the results of my search dynamicaly populate a table that displays my results.

the table should grow in width and height not to execeed 2 colums but to add as many rows as needed..

EX:

if my search retrieves 1 result then the table would have only 1 colum and 1 row but it 2 results are returned then the table should have 2 colums 1 row if 3 are returned then then have 2colums 2rows(cells with info) on the second row have one cell with infor and the other blank.

is this even possible?????
Avatar of TEFKASG
TEFKASG
Flag of United States of America image

Yes, it is possible.  :>)


<cfquery datasource="whatever it is" name="SearchResults">
Your query here
</cfquery>

<cfset toggle = 1>

<table>

 <cfoutput query="searchResults">

  <cfif toggle eq 1>  
    <tr> <td>Output search variable here </td>
    <cfset toggle = 2>
  <cfelseif toggle eq 2>
    <td>Output search variable here </td> </tr>
    <cfset toggle = 1?
  </cfif>

 </cfoutput>

  <cfif Toggle = 2>
   <td></td></tr>
  </cfif>

</table>
This is basically the bare bones way of doing it.  I assume you'll probably want column headings - just insert the row with the column heading before outputting the query.  If you need any addition explaination, just let me know and I'll give you a full description.  :>)

Cheers!
"<cfset toggle = 1?" is a typo. It should be <cfset toggle = 1>

:>)
Avatar of jriver12
jriver12

ASKER

TEFKASG,
I have tested the code that you gave(below)+ the code that I had existing and I received the following errors(look at the bottom of the page for error.  can you please clarify.
thanks.


<cfloop list="#form.results#" index="i_result" delimiters=",">

<CFQUERY NAME="searchit2" DATASOURCE="ProductCodes">
SELECT      dbo.Exhibitr.COMPANYNAME, dbo.Exhibitr.CompanyMailingAddress, dbo.Exhibitr.CompanyCity,



dbo.Exhibitr.CompanyState, dbo.Exhibitr.ZIP1, dbo.Exhibitr.CompanyPhone, dbo.Exhibitr.CompanyFax, dbo.Exhibitr.CompanyEmail,



dbo.PRODUCTS.DESCRIPTION
FROM         dbo.Exhibitr, dbo.EXHPROD_, dbo.PRODUCTS
WHERE       dbo.Exhibitr.ExhNum = dbo.EXHPROD_.ExhNUM AND
dbo.PRODUCTS.PRODNum = dbo.EXHPROD_.ProdNUM AND
(dbo.PRODUCTS.DESCRIPTION LIKE '#i_result#')
</CFQUERY>


<cfset toggle = 1>

<table>

<cfoutput query="searchit2">

 <cfif toggle eq 1>  
   <tr> <td>
   <!--- Output search variable here --->
Company: #COMPANYNAME# <br>
Address:#CompanyMailingAddress#<br>
CITY:  #CompanyCity# <BR>
STATE: #CompanyState#<BR>ZIP: #ZIP1#<br>
PHONE:#CompanyPhone#<br>
FAX:#CompanyFax#<br>
EMAIL: <a href=mailto:"#CompanyEmail#"> #CompanyEmail#</a></td>
   <cfset toggle = 2>
 <cfelseif toggle eq 2>
   <td>
   <!--- Output search variable here  --->
   Company: #COMPANYNAME# <br>
Address:#CompanyMailingAddress#<br>
CITY:  #CompanyCity# <BR>
STATE: #CompanyState#<BR>ZIP: #ZIP1#<br>
PHONE:#CompanyPhone#<br>
FAX:#CompanyFax#<br>
EMAIL: <a href=mailto:"#CompanyEmail#"> #CompanyEmail#</a></td> </tr>
   <cfset toggle = 1>
 </cfif>

</cfoutput>

 <cfif Toggle = 2>
  <td></td></tr>
 </cfif>

</table>
</cfloop>

Error code follows:

Error Diagnostic Information
Error in expression:

Toggle = 2

Invalid conditional expression. Perhaps you are using = instead of EQ or IS to compare values.

The error occurred while processing an element with a general identifier of (CFIF), occupying document position (97:2) to (97:18).

Opps, sorry about that! :>)

 <cfif Toggle = 2>
 <td></td></tr>
 </cfif>

Should be:

<cfif Toggle eq 2>
 <td></td></tr>
</cfif>
and now for an additional 25 points.

how do I pull the individual values of #i_result#.?

i have tried all I could figure and guess. but when I do get to show them they repeat for as many records as it pulled?

AAAARRHH!!!

  Could you clarify what exactly are you trying to do?  Where do you want to put the #i_result# value?

  You should be able to get it to display once, by placing the code for outputing the #i_result# value above the line:

<cfoutput query="searchit2">

 This should cause it to display once per iteration through your outer loop.
Sorry I was  kind of rambling.

However,

When the query is run and there are multiple search topics selected, the query runs and returns values based on the #I_Results#, the problem is that for each topic that the to pics is ran and records were found produces a new table for that topic, and repeats the header information for each table. is there a way to have all the results displayed in one table with the the results of the query displayed in the header just once ie... Products: item1, item2, item3:

here is what I have so far:

<cfloop list="#form.results#" index="i_result" delimiters=",">

 <CFQUERY NAME="searchit2" DATASOURCE="ProductCodes">
SELECT      dbo.Exhibitr.COMPANYNAME, dbo.Exhibitr.CompanyMailingAddress, dbo.Exhibitr.CompanyCity,



dbo.Exhibitr.CompanyState, dbo.Exhibitr.ZIP1, dbo.Exhibitr.tollfreenum, dbo.Exhibitr.CompanyPhone, dbo.Exhibitr.CompanyFax, dbo.Exhibitr.CompanyEmail,



dbo.PRODUCTS.DESCRIPTION
FROM         dbo.Exhibitr, dbo.EXHPROD_, dbo.PRODUCTS
WHERE       dbo.Exhibitr.ExhNum = dbo.EXHPROD_.ExhNUM AND
dbo.PRODUCTS.PRODNum = dbo.EXHPROD_.ProdNUM AND
(dbo.PRODUCTS.DESCRIPTION LIKE '#i_result#')
</CFQUERY>


<cfset toggle = 1>
  <body background="images/marb18.jpg" text="#000000" link="#0033FF" vlink="#FFFF66" alink="#0066FF">
 
  <table cellspacing="10" border="1" align="center" name="Show the results" width="621">

   
    <cfoutput query="searchit2">
      <cfif toggle eq 1>
      <tr>
        <td height="156" colspan="3"> <font face="Geneva, Arial, Helvetica, san-serif" size="3">
          <!--- Output search variable here --->
          <b>#COMPANYNAME#</b> <br>
          #CompanyMailingAddress#<br>
          #CompanyCity# <BR>
          #CompanyState#<BR>
          #ZIP1#<br>
          #tollfreeNUM#<bR>
          Phone:#CompanyPhone#<br>
          Fax:#CompanyFax#<br>
          <a href=mailto:"#CompanyEmail#"> #CompanyEmail#</a></font></td>
        <cfset toggle = 2>
        <cfelseif toggle eq 2>
        <td width="297" valign="top"> <font face="Geneva, Arial, Helvetica, san-serif" size="3">
          <!--- Output search variable here  --->
          <b>#COMPANYNAME#</b> <br>
          #CompanyMailingAddress#<br>
          #CompanyCity# <BR>
          #CompanyState#<BR>
          #ZIP1#<br>
          #tollfreeNUM#<bR>
          Phone:#CompanyPhone#<br>
          Fax:#CompanyFax#<br>
          <a href=mailto:"#CompanyEmail#"> #CompanyEmail#</a></font></td>
      </tr>
      <cfset toggle = 1>
      </cfif>
    </cfoutput>
    <cfif Toggle eq 2>
    <tr>
      <td height="2" colspan="3"></td>
      <td width="297"></td>
      <td width="11"></td>
    </tr>
    </cfif>
  </table>
  <br>
 
  <cfloop>
Okay.  :>)  You'll need to reorganize your code a little.  It should be as follows:

 
<body>

<table cellspacing="10" border="1" align="center" name="Show the results" width="621">

<*************** YOUR HEADER CODE HERE ************>

<cfloop list="#form.results#" index="i_result" delimiters=",">

<CFQUERY NAME="searchit2" DATASOURCE="ProductCodes">
SELECT      dbo.Exhibitr.COMPANYNAME, dbo.Exhibitr.CompanyMailingAddress, dbo.Exhibitr.CompanyCity,


dbo.Exhibitr.CompanyState, dbo.Exhibitr.ZIP1, dbo.Exhibitr.tollfreenum, dbo.Exhibitr.CompanyPhone, dbo.Exhibitr.CompanyFax,
dbo.Exhibitr.CompanyEmail,

dbo.PRODUCTS.DESCRIPTION
FROM         dbo.Exhibitr, dbo.EXHPROD_, dbo.PRODUCTS
WHERE       dbo.Exhibitr.ExhNum = dbo.EXHPROD_.ExhNUM AND
dbo.PRODUCTS.PRODNum = dbo.EXHPROD_.ProdNUM AND
(dbo.PRODUCTS.DESCRIPTION LIKE '#i_result#')
</CFQUERY>


<cfset toggle = 1>

<cfoutput query="searchit2">
     <cfif toggle eq 1>
     <tr>
       <td height="156" colspan="3"> <font face="Geneva, Arial, Helvetica, san-serif" size="3">
         <!--- Output search variable here --->
         <b>#COMPANYNAME#</b> <br>
         #CompanyMailingAddress#<br>
         #CompanyCity# <BR>
         #CompanyState#<BR>
         #ZIP1#<br>
         #tollfreeNUM#<bR>
         Phone:#CompanyPhone#<br>
         Fax:#CompanyFax#<br>
         <a href=mailto:"#CompanyEmail#"> #CompanyEmail#</a></font></td>
       <cfset toggle = 2>
       <cfelseif toggle eq 2>
       <td width="297" valign="top"> <font face="Geneva, Arial, Helvetica, san-serif" size="3">
         <!--- Output search variable here  --->
         <b>#COMPANYNAME#</b> <br>
         #CompanyMailingAddress#<br>
         #CompanyCity# <BR>
         #CompanyState#<BR>
         #ZIP1#<br>
         #tollfreeNUM#<bR>
         Phone:#CompanyPhone#<br>
         Fax:#CompanyFax#<br>
         <a href=mailto:"#CompanyEmail#"> #CompanyEmail#</a></font></td>
     </tr>
     <cfset toggle = 1>
     </cfif>
   </cfoutput>
   <cfif Toggle eq 2>
   <tr>
     <td height="2" colspan="3"></td>
     <td width="297"></td>
     <td width="11"></td>
   </tr>
   </cfif>
 
 <br>
 
 <cfloop>

</table>

  This should put all of your results in a single table with a single header at the top.  
thanks it worked great, and I appreciate your time and assistance.
Glad I could be of help.  :>)

Cheers!
ASKER CERTIFIED SOLUTION
Avatar of TEFKASG
TEFKASG
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial