pls suggest me......

Last post 05-10-2008 7:20 AM by Abitha. 3 replies.

Sort Posts:

  • pls suggest me......

    05-10-2008, 1:20 AM
    • Loading...
    • Abitha
    • Joined on 02-14-2008, 2:56 AM
    • Posts 89

    hi

    i am using html checkboxes to let user to select categories in which search has to be done. there are  4 checkboxes for 4 categories.

    this query i have checked in query anakyzer. this query is working and displaying results.acc to this query user has selected "3 checkboxes" and entered "airports" to search.

    SELECT * FROM tbl_Arab_Newsletter WHERE (Month(month) = '2' AND year(month) = '2008') and (cat_number = 1 or cat_number = 2 or cat_number = 3) and (story like '%airports%' )

    i have written code like this.

    strSQL = "SELECT * FROM tbl_Arab_Newsletter WHERE (Month(month) = '"& m &"' AND year(month) = '"& y &"')"

    strSQL = strSQL & " and cat_number = 1"

    end if

    if cat2="on" then 'check box 2 is enabled means this condition

    strSQL = strSQL & " and cat_number = 2"

    end if

    if cat3="on" then 'check box 3 is enabled means this condition

    strSQL = strSQL & " and cat_number = 3"

    end if

    if cat4="on" then 'check box 4 is enabled means this condition

    strSQL = strSQL & " and cat_number = 4"

    end if

    strSQL = strSQL & " and (story like '%" & search & "%')"

    but this statements are not working. how to write the if conditon  acc to the query. pls help and if dont mind pls give me the correct code.

    thank u.

     

     

  • Re: pls suggest me......

    05-10-2008, 2:33 AM
    Answer

    in your query the condition is like, 

    and (cat_number = 1 or cat_number = 2 or cat_number = 3)

    but you are writing cu a way as

    and cat_number = 1 and cat_number = 2 and cat_number = 3

    Now try this ,

     

    strSQL = "SELECT * FROM tbl_Arab_Newsletter WHERE (Month(month) = '"& m &"' AND year(month) = '"& y &"')"

    strSQL = strSQL & " and ( cat_number = 1"

    end if

    if cat2="on" then 'check box 2 is enabled means this condition

    strSQL = strSQL & " or cat_number = 2"

    end if

    if cat3="on" then 'check box 3 is enabled means this condition

    strSQL = strSQL & " or cat_number = 3"

    end if

    if cat4="on" then 'check box 4 is enabled means this condition

    strSQL = strSQL & "  or cat_number = 4"

    end if

    strSQL = strSQL & ")"

    strSQL = strSQL & " and (story like '%" & search & "%')"

  • Re: pls suggest me......

    05-10-2008, 2:39 AM
    • Loading...
    • Avinash Desai
    • Joined on 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 717

    Hey

    I have Some doubts See is you are using the Check box is the user selects all 3 then how will you query...I think thats Wrong as you have mentioned in your code

    Abitha:

    SELECT * FROM tbl_Arab_Newsletter WHERE (Month(month) = '2' AND year(month) = '2008') and (cat_number = 1 or cat_number = 2 or cat_number = 3) and (story like '%airports%' )

    i have written code like this.

     

    If you have Used Checkbox then the in the select statement you have to use all 3 check box values to query data..If you are using only one Cat_Number then better to use Radio Button ....If my understanding is wrong  then please can you explain more about the Checkbox selection and the Select query you require Because if user has selected all 3 chekbox then the cat_Number will come for 3 then your query goes wrong ....
     

    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: pls suggest me......

    05-10-2008, 7:20 AM
    • Loading...
    • Abitha
    • Joined on 02-14-2008, 2:56 AM
    • Posts 89

    hi!

    thanks for ur suggestion. i got the solution.

    thanks a lott.

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter