SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    equiv of % for int field?

    I have a sql query that has a Where caluse based on an integer value. The problem I have is that I want to be able to pass a default value to get all of them ( like using a % symbol to get any string ), but I can't figure out what I need, I have tried * and such.

    Here is the query:
    PHP Code:
     $query "Select * FROM student INNER JOIN person on person.ID = student.PersonID WHERE Year = $Year ORDER BY lname, fname"
    The Year value is what I am trying to get to work out.

    Thanks for the help
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    If you drop the where clause, all rows will be returned

    PHP Code:
    $query "Select * FROM student INNER JOIN person on person.ID = student.PersonID ORDER BY lname, fname"

  3. #3
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol

    Yea, I was just trying to reuse a function rather than create two.

    Thanks though.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming that the year is normally passed as 4 digits, why don't you use zero as your special value?
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  5. #5
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the year is not that kind of year. We have students that are either 1st year, 2nd year, 3rd, 4th. Because it is not tied with a date I just have a field that tracks which they are with a single digit.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    the best way to deal with this situation is to code your app to handle both situations -- either a value is passed in or it isn't -- and construct the sql accordingly

    failing that, you could consider doing some sql injection of your own

    try running the query with $Year set to 9 or 1=1

    rudy

  7. #7
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am thinking about changing the database field to a single char and then limiting the values to 1-4 in the validation code I use. I really have no need to deal with it as a number expect for the fact that it is just a number. I can treat like a char I think and everything I already have will work. I just need to add a bunch of quotes to all the funtion calls.

    Thanks for the help on this. Sometimes you just don't see it all right the first time you lay it out. :-)
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  8. #8
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just do it as M@rco suggested. That way you can leave the Year field as numeric field.

    Code:
    $query = "SELECT *
    FROM student
    INNER JOIN person on person.ID = student.PersonID
    WHERE ($Year = 0 OR Year = $Year)
    ORDER BY lname, fname";

  9. #9
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the tips. I did try it out with shane's suggestion for modifying the query and it works.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."


Bookmarks

Posting Permissions

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