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 5 of 5

Thread: MySQL Searching

  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL Searching

    Im creating a recordset filters on orderPaymentReceived,
    The code below works fine.

    However i need to replace the "y" with a varible, $source which will hold with y or n.

    $result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = 'y'");

    //---------------------------------------------------
    My previous attempt
    $result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = ". $source);

    Dosnt work.

  • #2
    New Coder
    Join Date
    May 2004
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL Searching

    Try this

    $result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = `". $source."`);

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by LynxGrr
    Try this

    $result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = `". $source."`);
    Welcome here LynxGrr !

    Why backticks? + you need to close the double quotes at the end

    $result = mysql_query("SELECT * FROM tblOrders WHERE orderPaymentReceived = '". $source."'");

    Niko : never use * --> always specify the columns you need + you need to add some errorhandling. So your codeshould look like:

    $result = mysql_query("SELECT var1, var2, var3 FROM tblOrders WHERE orderPaymentReceived = '". $source."'") or die ('Queryproblem when selecting orderdetails');

    (replace italics with your columnnames)
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    New Coder
    Join Date
    May 2004
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Whoops!

    Ive used backticks since i started, makes it easier to see against a " and Ive had no probs with it!

    As for the closing "..... whoops! my bad!

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by LynxGrr
    Ive used backticks since i started, makes it easier to see against a " and Ive had no probs with it!
    Backticks are for escaping columnnames/tablenames/dbnames that are, for instance, reserved words. To me (and probably other coders), it looks very confusing, because i expect a table/columnname between them and i was initially thinking it was a generic query
    (as inside a "where table1.var1=`table2.order`" )

    It's maybe unlikly but if you ever get a value like 'blabla.bla' or maybe less unlikely '23333.567' then i would expect your query to error out
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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