NOT results query

Discussion in 'PHP' started by lektrikpuke, Jul 21, 2008.

  1. #1
    Hi y'all,

    I have a php search that queries a mysql DB. Works fine for my needs, but I'd like to add a NOT function (if you will) to the query. So, word(s) not word(s), or word(s) -word(s). It would be nice to implement this filtering capability as the DB is getting large enough to return too many results (even though the presentation is paginated).

    Any ideas?

    Thanks.

    Robert :D
     
    lektrikpuke, Jul 21, 2008 IP
  2. rajug

    rajug Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Better you post your current code so that experts here can see and say the solution. Just words,not words... etc wont be enough to understand AFAIK.
     
    rajug, Jul 21, 2008 IP
  3. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    SELECT * FROM table WHERE something = 'item' AND something != 'item'
    
    Code (markup):
    "=" is equals
    and "!" stands for "does not" so "!=" is "does not equal"

    Hope that helps.

    PS: rajug, what he supplied is more than sufficient for me, and I wouldn't even consider myself an expert. ;)
     
    Cri2T, Jul 21, 2008 IP
  4. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #4
    Thanks. Should have thought of that myself. :)
     
    lektrikpuke, Jul 22, 2008 IP
  5. Silas101

    Silas101 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i think i have a similar problem... using mysql.

    on my one page i have 3 input values $datefrom $dateto $branch
    I can display these values on my second form

    but if i try and use them in my sql i get errors to do with initializing sessions

    i want to run this query

    select Amount,date,branch from table where date between $datefrom and $dateto and brn=$branch

    if i run that query without the where part i get nice results if i add that where part i get errors.

    how do i use those $ values in my sql?
     
    Silas101, Jul 23, 2008 IP
  6. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #6
    I'm guessing you have an order problem (I assume $branch is not a date).

    Try:

    select Amount,date,branch from table where brn=$branch and date between $datefrom and $dateto
     
    lektrikpuke, Jul 23, 2008 IP
  7. Silas101

    Silas101 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Okay branch is like region as in city or town

    the amounts are for different cities and dates

    if i try to use $field i the sql i get an error.
    you can try and open the page at URL="http://www.gravityweb.co.za/core/services.htm"]gravityweb[/URL] try the branch totals link

    The sql Below WORKS

    // sending query to show records between $datefrom and $dateto and branch=$brn only
    $result = mysql_query("SELECT branch_name,Date,Time,Receipt_No,Amount_Paid,Payment_Type,Payment_By FROM {$table} ORDER BY Branch,Date desc");
    if (!$result) {
    die("Query to show fields from table failed");

    If i add where Date between $datefrom and $dateto then i get the error
     
    Silas101, Jul 23, 2008 IP
  8. Silas101

    Silas101 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is the error i get if i add $field into my sql

    Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
     
    Silas101, Jul 23, 2008 IP
  9. Silas101

    Silas101 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i seemed to have found the solution by retrieving the value from the session thingie and then using that in the sql. the error does not appear anymore but i think now i just have to find a way to convert the values to a date so my sql will return records. for now there is no more error and the result is just blank with only the field names returned in one record.

    Thanks
     
    Silas101, Jul 24, 2008 IP