Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Problem displaying the right results from my form to the results table

The History of this started from
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21155027.html

Thank you for your help.  I modified the query and it works fine but the result page does not seem to output the right results.

I want the users to search with ItemNo and any other data and have the result page show the search criteria. e.g if I search with ItemNo and Date, I want the reult page to show the itemno, date and any other data I want.

I have the following query for the result page:

<cfparam name="FORM.AgendaItemNo" default="">
<cfparam name="FORM.Comm_CouncilDate" default="">
<cfparam name="FORM.Comm_CouncilName" default="">
<cfquery name="spResults" datasource="SpeakerCard">
SELECT *
FROM SpeakerCard
WHERE AgendaItemNo IN ('#FORM.AgendaItemNo#', '#FORM.Comm_CouncilDate#', '#FORM.Comm_CouncilName#')
ORDER BY SpeakerCard.AgendaItemNo, Comm_CouncilDate, Comm_CouncilName</cfquery>

Then I have my output table.

How do I fix this
0
iolike
Asked:
iolike
1 Solution
 
pinaldaveCommented:
Hi iolike,
 
what is borken? The question is not clear.
If you want to dispaly the form field in teh table you can do like from query it will be like that... if you want form variable then replace queryname.variable with form.youravariable
<cfoutput>
<table>
<tr>
<td>
#spresutls.yourvariable#
</td>
</tr>
<table>
</cfoutput>
Regards,
---Pinal
0
 
CFDevHeadCommented:
Yes, it is still unclear as to what you want to do.
0
 
CFDevHeadCommented:
>>" I want the reult page to show the itemno, date and any other data I want."

if the query works fine and you just want help outputing I would do something like this.

<cfoutput>
<table>
      <tr>
            <td>ItemNo</td>
            <td>Date</td>
            <td>Other Data</td>
      </tr>
      <cfloop query="spResults">
      <tr class="">#iif(current mod 2,'"altbg"','""')#
            <td>ItemNo</td>
            <td>Date</td>
            <td>Other Data</td>
      </tr>
      </cfloop>      
</table>
</cfoutput>
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mrichmonCommented:
Perhaps showing an example of what output you are getting versus what output you want.....
0
 
campbelcCommented:
Try this:


<cfparam name="form.ConNumber" default="%">
<cfparam name="form.ItemNo" default="">
<cfparam name="form.Name" default="">
<cfparam name="form.Date" default="">
<cfquery name="SearchForm" datasource="ChrisForTest">
  SELECT * FROM SpeakerCard WHERE 0=0
    <cfif form.ConNumber NEQ "">AND ConNumber LIKE '%#form.ConNumber#%'</cfif>
    <cfif form.ItemNo NEQ "">AND ItemNo = '#form.ItemNo#'</cfif>
    <cfif form.Name NEQ ""> AND Name= '#form.Name#'</cfif>
    <cfif form.Date NEQ ""> AND Date = '#form.Date#'</cfif>
</cfquery>

<title>Speaker Card Search Form</title>

<style type="text/css">
<!--
  .style1 {font-family: Arial, Helvetica, sans-serif;font-size: 14px;font-weight: bold;}
  .style2 {font-size: 16px}
  .style3 {font-family: Arial, Helvetica, sans-serif;font-size: 11px;font-weight: bold;color:#ffffff;}
-->
</style>
</head>

<body bgcolor="#CCFFFF">
<p align="center" class="style1 style2"><strong>Search Form</strong></p>
<table width="25%" align="center" >
  <tr>
    <td><div align="center" class="style14 style17"><strong><cfoutput>#DateFormat(Now(), "mmmm dd, yyyy")#</cfoutput> </strong></div></td>
    <td><cfoutput><span class="style14 style1 style17"><strong>#TimeFormat(Now(), "hh:mm:sstt")#</strong></span></cfoutput></td>
  </tr>
</table>
<div align="right">
  <input type="submit" name="Submit2" value="Back to Menu Page" style="font:Arial, Helvetica, sans-serif; font-size:12px; font-weight:bolder" onClick="window.open('SearchandReportMenu.cfm');" onMouseOver="this.style.color='red';" onMouseOut="this.style.color='black';" >
</div>
<hr size="5" color="#333333">
<form action="blah.cfm?a=results" method="post" name="SearchForm" id="SearchForm">
  <p align="center" class="style1">Con<br>
    Number:<br>
    <input name="ConNumber" type="text" id="ConNumber" size="20" maxlength="25">    
    <br>
    <br>
    Item Number/<br>
    <input name="ItemNo" type="text" id="ItemNo" size="30" maxlength="35">
  </p>
  <p align="center" class="style1">Name:<br>
    <select name="Name" size="1" id="Name">
      <option value=""></option>
      <cfoutput query="SearchForm">
      <option value="#SearchForm.Name#">#SearchForm.Name#</option>
    </cfoutput>    
    </select>
  </p>
<p align="center" class="style1">Date:<br>
    <select name="Date" size="1" id="Date">
      <option value=""></option>
      <cfoutput query="SearchForm">
      <option value="#SearchForm.Date#">#SearchForm.Date#</option>
    </cfoutput>    
    </select>
  </p>
    <p align="center" class="style1"><span class="style1">
    <input type="submit" name="Submit" value="Search">
  </span> </p>
</form>
<p>&nbsp;</p>

<cfif isdefined("url.a")>
  <cfquery name="SearchForm2" datasource="ChrisForTest">
    SELECT * FROM SpeakerCard WHERE 0=0
      <cfif form.ConNumber NEQ "">AND ConNumber LIKE '%#form.ConNumber#%'</cfif>
      <cfif form.ItemNo NEQ "">AND ItemNo = '#form.ItemNo#'</cfif>
      <cfif form.Name NEQ ""> AND Name= '#form.Name#'</cfif>
      <cfif form.Date NEQ ""> AND Date = '#form.Date#'</cfif>
  </cfquery>

  <table align="center" width="700" cellpadding="3" cellspacing="1" bgcolor="cccccc">
    <tr bgcolor="808080">
        <td class="style3">Con Number:</td>
        <td class="style3">Item Number:</td>
        <td class="style3">Name:</td>
        <td class="style3">Date:</td>
    </tr>
    <cfoutput query="searchform2">
    <tr bgcolor="ffffff">
        <td>#connumber#</td>
        <td>#itemno#</td>
        <td>#name#</td>
        <td>#date#</td>
    </tr>
    </cfoutput>
  </table>
</cfif>

</body>
</html>


0
 
campbelcCommented:
Sorry, try this:

<cfquery name="SearchFormNames" datasource="ChrisForTest">
  SELECT * FROM SpeakerCard order by name
</cfquery>
<cfquery name="SearchFormDates" datasource="ChrisForTest">
  SELECT * FROM SpeakerCard order by date
</cfquery>

<title>Speaker Card Search Form</title>

<style type="text/css">
<!--
  .style1 {font-family: Arial, Helvetica, sans-serif;font-size: 14px;font-weight: bold;}
  .style2 {font-size: 16px}
  .style3 {font-family: Arial, Helvetica, sans-serif;font-size: 11px;font-weight: bold;color:#ffffff;}
-->
</style>
</head>

<body bgcolor="#CCFFFF">
<p align="center" class="style1 style2"><strong>Search Form</strong></p>
<table width="25%" align="center" >
  <tr>
    <td><div align="center" class="style14 style17"><strong><cfoutput>#DateFormat(Now(), "mmmm dd, yyyy")#</cfoutput> </strong></div></td>
    <td><cfoutput><span class="style14 style1 style17"><strong>#TimeFormat(Now(), "hh:mm:sstt")#</strong></span></cfoutput></td>
  </tr>
</table>
<div align="right">
  <input type="submit" name="Submit2" value="Back to Menu Page" style="font:Arial, Helvetica, sans-serif; font-size:12px; font-weight:bolder" onClick="window.open('SearchandReportMenu.cfm');" onMouseOver="this.style.color='red';" onMouseOut="this.style.color='black';" >
</div>
<hr size="5" color="#333333">
<form action="blah.cfm?a=results" method="post" name="SearchForm" id="SearchForm">
  <p align="center" class="style1">Con<br>
    Number:<br>
    <input name="ConNumber" type="text" id="ConNumber" size="20" maxlength="25">    
    <br>
    <br>
    Item Number/<br>
    <input name="ItemNo" type="text" id="ItemNo" size="30" maxlength="35">
  </p>
  <p align="center" class="style1">Name:<br>
    <select name="Name" size="1" id="Name">
      <option value=""></option>
      <cfoutput query="SearchFormNames">
      <option value="#SearchFormNames.Name#">#SearchFormNames.Name#</option>
    </cfoutput>    
    </select>
  </p>
<p align="center" class="style1">Date:<br>
    <select name="Date" size="1" id="Date">
      <option value=""></option>
      <cfoutput query="SearchFormDates">
      <option value="#SearchFormDates.Date#">#SearchFormDates.Date#</option>
    </cfoutput>    
    </select>
  </p>
    <p align="center" class="style1"><span class="style1">
    <input type="submit" name="Submit" value="Search">
  </span> </p>
</form>
<p>&nbsp;</p>

<cfif isdefined("url.a")>
  <cfquery name="SearchForm2" datasource="ChrisForTest">
    SELECT * FROM SpeakerCard WHERE 0=0
      <cfif form.ConNumber NEQ "">AND ConNumber LIKE '%#form.ConNumber#%'</cfif>
      <cfif form.ItemNo NEQ "">AND ItemNo = '#form.ItemNo#'</cfif>
      <cfif form.Name NEQ ""> AND Name= '#form.Name#'</cfif>
      <cfif form.Date NEQ ""> AND Date = '#form.Date#'</cfif>
  </cfquery>

  <table align="center" width="700" cellpadding="3" cellspacing="1" bgcolor="cccccc">
    <tr bgcolor="808080">
      <td class="style3">Con Number:</td>
      <td class="style3">Item Number:</td>
      <td class="style3">Name:</td>
      <td class="style3">Date:</td>
    </tr>
    <cfoutput query="searchform2">
    <tr bgcolor="ffffff">
      <td>#connumber#</td>
      <td>#itemno#</td>
      <td>#name#</td>
      <td>#date#</td>
    </tr>
    </cfoutput>
  </table>
</cfif>
</body>
</html>
0
 
campbelcCommented:
Sorry, keep adding more and more features on to this: =)


<cfquery name="SearchFormNames" datasource="ChrisForTest">
  SELECT * FROM SpeakerCard order by name
</cfquery>
<cfquery name="SearchFormDates" datasource="ChrisForTest">
  SELECT * FROM SpeakerCard order by date
</cfquery>

<title>Speaker Card Search Form</title>

<style type="text/css">
<!--
  .style1 {font-family: Arial, Helvetica, sans-serif;font-size: 14px;font-weight: bold;}
  .style2 {font-size: 16px}
  .style3 {font-family: Arial, Helvetica, sans-serif;font-size: 11px;font-weight: bold;color:#ffffff;}
-->
</style>
</head>

<body bgcolor="#CCFFFF">
<p align="center" class="style1 style2"><strong>Search Form</strong></p>
<table width="25%" align="center" >
  <tr>
    <td><div align="center" class="style14 style17"><strong><cfoutput>#DateFormat(Now(), "mmmm dd, yyyy")#</cfoutput> </strong></div></td>
    <td><cfoutput><span class="style14 style1 style17"><strong>#TimeFormat(Now(), "hh:mm:sstt")#</strong></span></cfoutput></td>
  </tr>
</table>
<div align="right">
  <input type="button" name="Submit2" value="Back to Menu Page" style="font:Arial, Helvetica, sans-serif; font-size:12px; font-weight:bolder" onClick="window.open('SearchandReportMenu.cfm');" onMouseOver="this.style.color='red';" onMouseOut="this.style.color='black';" >
</div>
<hr size="5" color="#333333">
<form action="report.cfm?a=results" method="post" name="SearchForm" id="SearchForm">
  <p align="center" class="style1">Con<br>
    Number:<br>
    <input name="ConNumber" type="text" id="ConNumber" size="20" maxlength="25">    
    <br>
    <br>
    Item Number/<br>
    <input name="ItemNo" type="text" id="ItemNo" size="30" maxlength="35">
  </p>
  <p align="center" class="style1">Name:<br>
    <select name="Name" size="1" id="Name">
      <option value=""></option>
      <cfoutput query="SearchFormNames" group="name">
      <option value="#SearchFormNames.Name#">#SearchFormNames.Name#</option>
    </cfoutput>    
    </select>
  </p>
<p align="center" class="style1">Date:<br>
    <select name="Date" size="1" id="Date">
      <option value=""></option>
      <cfoutput query="SearchFormDates" group="date">
      <option value="#SearchFormDates.Date#">#SearchFormDates.Date#</option>
    </cfoutput>    
    </select>
  </p>
    <p align="center" class="style1"><span class="style1">
    <input type="submit" name="Submit" value="Search">
  </span> </p>
</form>
<p>&nbsp;</p>

<cfif isdefined("url.a")>
  <cfquery name="SearchForm2" datasource="ChrisForTest">
    SELECT * FROM SpeakerCard WHERE 0=0
      <cfif form.ConNumber NEQ "">AND ConNumber LIKE '%#form.ConNumber#%'</cfif>
      <cfif form.ItemNo NEQ "">AND ItemNo = '#form.ItemNo#'</cfif>
      <cfif form.Name NEQ ""> AND Name= '#form.Name#'</cfif>
      <cfif form.Date NEQ ""> AND Date = '#form.Date#'</cfif>
  </cfquery>
  <cfif SearchForm2.RecordCount EQ 0>
    <script language="javascript">
        alert('Your search found 0 records');
        self.location='report.cfm';
      </script>  
  </cfif>
  <table align="center" width="700" cellpadding="3" cellspacing="1" bgcolor="cccccc">
    <tr bgcolor="808080">
        <td class="style3">Con Number:</td>
        <td class="style3">Item Number:</td>
        <td class="style3">Name:</td>
        <td class="style3">Date:</td>
    </tr>
    <cfoutput query="searchform2">
    <tr bgcolor="ffffff">
        <td>#connumber#</td>
        <td>#itemno#</td>
        <td>#name#</td>
        <td>#date#</td>
    </tr>
    </cfoutput>
  </table>
</cfif>
<script language="javascript">
  document.SearchForm.ConNumber.focus();
</script>
</body>
</html>
0
 
campbelcCommented:
Woops, this is using the database fields from your last question. Will modify to work for this question.
0
 
campbelcCommented:
Need this rewritten or can you figure it based on the last question? Let me know. =)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now