Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Conditional search, if not found...

    Hi

    I have a database where some students don't have their Identity_number stored , but all students have a code.

    I am trying to implement a search in this database with some degree of safety.

    In first html page, both fields are mandatory (because everbody has an Identity_number to type )

    $result = mysql_query("SELECT * FROM certificado WHERE Identity_number= '$cpf'") or die (mysql_error());

    If found Identity_number, compare certificado.code with $code and show (html result - a already have) if match.

    However if Identity_number is not found, then search only by code. ( because nobody will guess student does not have Identity_number in database .)

    Is it easy to do such a code ? I need help at least with $result mysql lines.
    Moises

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    429
    Thanks
    0
    Thanked 20 Times in 20 Posts
    either give them all an 'Identity_number' or only do a code search.

    "some students don't have their Identity_number stored , but all students have a code."
    "both fields are mandatory (because everbody has an Identity_number to type )" false according to first sentence.
    NO Limits!! www.dhcreationstation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com

  • #3
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by moisesbr View Post
    Hi

    I have a database where some students don't have their Identity_number stored , but all students have a code.

    I am trying to implement a search in this database with some degree of safety.

    In first html page, both fields are mandatory (because everbody has an Identity_number to type )

    $result = mysql_query("SELECT * FROM certificado WHERE Identity_number= '$cpf'") or die (mysql_error());

    If found Identity_number, compare certificado.code with $code and show (html result - a already have) if match.

    However if Identity_number is not found, then search only by code. ( because nobody will guess student does not have Identity_number in database .)

    Is it easy to do such a code ? I need help at least with $result mysql lines.
    Moises
    The standard mysql functions in PHP are on the way out, so you should write this with either PDO or mysqli instead. It is also advisable to use "prepared statements" for the query (we can dig into this part later, feel free to look it up in the meantime).

    Do you expect to have more than one row returned from such a query? Or will each student only have one row in the table (i.e. is "Identity_number" set up with the "unique" constraint in the table)?
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting


  •  

    Posting Permissions

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