MySQL confuses me.

Discussion in 'PHP' started by IceGuru, Feb 13, 2012.

  1. #1
    Here is what I'm trying to do.
    I need to check to see if a student has already been requested for that date and if so I need to check to see if the priority level is higher. If that returns no results I need to add the info to the table.

    I have these fields:

    student VARCHAR(150)
    class VARCHAR(150)
    date_requested INT(6)
    date_added INT(6)
    priority (2)
     
    IceGuru, Feb 13, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    why not make a unique on student/date so there can be only one student with that unique date.

    But still not getting what you want, with a list of your table nothing is said here!
     
    EricBruggema, Feb 14, 2012 IP
  3. IceGuru

    IceGuru Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I need the SQL part of the code ... what I keep trying doesn't work.

    and no I want the old records to stay for a record.
     
    IceGuru, Feb 14, 2012 IP
  4. ApocalypseXL

    ApocalypseXL Notable Member

    Messages:
    6,095
    Likes Received:
    103
    Best Answers:
    5
    Trophy Points:
    240
    #4
    As Eric suggested made sure that the exact value of requested already exists . Also please post more info we can barely understand what your script is doing . IDK where you get the input and what the script is suppose to do . Also please make a ID field with autoincrement , that's just good coding practice .
     
    ApocalypseXL, Feb 14, 2012 IP
  5. adityamenon

    adityamenon Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Kindly post your MySQL query, and if possible the accompanying PHP code here. Did you try anything just yet?

    Also, please explain this: who is 'requesting' for students? Or are the students requesting for lessons? This relationship is slightly unclear so it is hard to answer.
     
    adityamenon, Feb 14, 2012 IP
  6. IceGuru

    IceGuru Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It's a page where my teachers will request an array of students for their class on a certain date.
     
    IceGuru, Feb 14, 2012 IP
  7. adityamenon

    adityamenon Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #7
    
    SELECT priority, date_requested FROM table_name WHERE student = "student-name"
    
    Code (markup):
    Once you get that out, you can do the processing for priority checking and date uniqueness checking within your PHP code. I usually prefer dumb databases and like to send as less processing overhead as possible to the DB.
     
    adityamenon, Feb 14, 2012 IP
  8. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #8
    Post your code thus far or at least a portion of it.
     
    Andre91, Feb 14, 2012 IP
  9. idotcom

    idotcom Well-Known Member

    Messages:
    522
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #9
    This help?

    SELECT * FROM table WHERE student='$student' AND date_added='$date' AND priority>5
     
    idotcom, Feb 15, 2012 IP
  10. IceGuru

    IceGuru Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I got it now thanks for all your help guys. :)

    iceguru.kodingen.com/schoolproject/
     
    IceGuru, Feb 15, 2012 IP