Results 1 to 7 of 7

Thread: Is my query correct ?

  1. #1

    Is my query correct ?

    I have written the following query:
    PHP Code:
    $edu $_POST['edu'];
                    if(
    $edu == "SLC")
                        {
                            
    $for "`slc` != ''";
                        }
                        elseif(
    $edu == "+2")
                        {
                            
    $for "`inter` != ''";
                        }
                        elseif(
    $edu == "Bachelor")
                        {
                            
    $for "`bachelor` != '' or `edu1` like 'b%' or `edu2` like 'b%'";
                        }
                        elseif(
    $edu == "Master")
                        {
                            
    $for "`master` != '' or `edu1` like 'm%' or `edu2` like 'm%'";
                        }
                        elseif(
    $edu == "Phd")
                        {
                            
    $for "`edu1` like '%phd%' or `edu2` like '%phd%'";
                        }
                        if(
    $edu == "ANY")
                        {
                            
    $for "`slc` = '%'";
                        } 
    Code:
    select * from resumes where $for and SUM(exp1months + exp2months + exp3months) as ex >= $exp1 like '%$exp1%' and `interest` like '%$interest1%' and status = 1 order by id desc
    This query gives me thsi result when i echo it.
    Code:
    select * from resumes where `bachelor` != '' or `edu1` like 'b%' or `edu2` like 'b%' and SUM(`exp1months` + `exp2months` + `exp3months`) as `ex` >= 2 like '%2%' and `interest` like '%%' and status = 1 order by id desc
    And returns no result.

    Can you tell me where am i going Wrong?

  2. #2
    probably way to and conditions not being met
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  3. #3
    any idea how to do that?

  4. #4
    Quote Originally Posted by utsav View Post
    any idea how to do that?
    meant to say way to many and conditions not being met. basically you're telling the query that it can be

    a OR b OR c OR d AND e AND f AND g AND h

    if all of e, f, g and h conditions aren't met you're gonna get 0 results
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    You might want to put brackets around your 'or'

    Also this query fails because
    • the SUM line cannot compare to 2 and also have the like comparison directly after it?
    • interest is being compared to 2 nothing(everything)



    Code:
    select *
    from resumes
    where `bachelor` != '' or 
    `edu1` like 'b%' or 
    `edu2` like 'b%' and 
    SUM(`exp1months` + `exp2months` + `exp3months`) as `ex` >= 2 like '%2%' and 
    `interest` like '%%' and 
    status = 1
    order by id desc

  6. #6
    Ok thanks both of you, Will try that and let you know if it works.

  7. #7
    No worries, just for example this is what I meant:

    Code:
    select *
    from resumes
    where 
    (`bachelor` != '' or `edu1` like 'b%' or `edu2` like 'b%') and 
    SUM(`exp1months` + `exp2months` + `exp3months`) as `ex` >= 2 and 
    `interest` like '%something%' and 
    status = 1
    order by id desc
    Let us know how you go.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012