Skip to main content
Participant
April 20, 2009
Question

how to approach this problem

  • April 20, 2009
  • 1 reply
  • 897 views

        I am displaying a dynamic table  which consits of four columns named as Ingredient,Lot,d_amount,d_unit......out of which Ingredient,d_amount,d_unit are taken from one

query named as "qrecipes" i.e from one table and Lot Cloumn is taken from another table.Now the problem is the data that is to be displayed in lot column is dependent on the

data present in ingredient.i.e If the first row ingredient column has "XYZ" then i need to pick the id of "XYZ" from second table and display in lot column.


              Ingredient   Lot            d_amount     d_unit

        1   xyx       345 is id
                           for XYZ which
                          should be
            displayed from
            Second table


Below is my code ....please say what is wrong .....please suggest me if there are any other methods or any kind of solution to solve this problem

Queirs

<cfquery name="qrecipes" datasource="testmsexcell">
SELECT *
FROM Recipes WHERE product='#form.product#'

</cfquery>


<cfquery name="qlot"  datasource="testmsexcell">
SELECT Lots.id
FROM Lots WHERE ingredient='#qrecipes.ingredient#'
</cfquery>


Table

                               table border="2px" id="maketable">
                                    <tr>
                                     
                                      <td>Ingredient</td>
                                      <td>Lot</td>
                                      <td>d_amount</td>
                                      <td>d_unit</td>
                                    </tr>
                                    <cfoutput query="qrecipes">
                                      <tr>
                                      
                                        <td>#qrecipes.ingredient#</td>
                                        <td><cfselect name="lotid" id="lotid" query="qlot" value="id" display="id"></cfselect></td>
                                        <td>#qrecipes.d_amount#</td>
                                        <td>#qrecipes.d_unit#</td>
                                      </tr>
                                    </cfoutput>
                                  </table>

    This topic has been closed for replies.

    1 reply

    Inspiring
    April 20, 2009

    Combine the two queries into one by joining the tables.  If you don't know how, I've heard good things about the book "Teach Yourself SQL in 10 Minutes" by Ben Forta.

    nagkarAuthor
    Participant
    April 20, 2009

    Thanks. for the reply.....but i tried a lot and i was unsucesful.below are my table.....can you please say the sql query

    i have kept those dots to have a table appreance...neglect those dots


    First Table is Recipes

    Product...........ingredient.........d_amount.......... d_unit id
    abc................xyz...............78................... lb.....     
    ....................uvw...........................................

    efg..................hig
    ......................lkm

    In the first table the id is the primarykey which is autoincremented.

    Second Table is Lot:The id is primarykey which is not related to first  table which is recipes.

    id.............ingredient

    5t6y.............xyz
    7yh8.............xyz
    9jnu.............uvw


    Now i am trying to diaplay to user something like this by taking product as input from the user.if the user selects product as "abc"


    ingredient........lotids............d_amount.......d_unit

    xyz...............5t6y
    ...................7yh8


    uvw.................9jnu

    I am able to display the ingredient,d_amount,d_unit correctly but i am unable to display the correct lotids for the repective ingredient.I am using CFSELECT tag to display the lotids

    ilssac
    Inspiring
    April 20, 2009