SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Need PHP code to make mySQL query dynamic

    I have a standard query shown down below. However, I want the ability to week out people who don't live in the US or Canada. So here is what I have done:

    if($session_displayForeign != "on") {
    $moreCriteria .= " AND (country = 'United States' or country = 'Canada'";
    }

    I want to be able to add this additional criteria in the main query below.

    if ($type == "reviewedCD") {
    $query = "SELECT contactID, date, firstName, lastName, state, country, phone, available, needs, modified FROM contacts where ownerID = '$session_ownerID' and interest <> 'None' and reviewed = 'No' and needsKit = 'No' and modified <> '$today'".$moreCriteria." order by $sort";}

    I currently get this error message:

    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by modified' at line 1

    Can anyone help? I think I'm using concatination wrong with $moreCriteria.

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    Awesome Addict
    Join Date
    Mar 2004
    Location
    Toronto, Canada
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you echo $query somewhere and then paste it here so that we can see the full SQL statement?

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I did that and found that I was missing the closing ) Thank you!
    Convert your dollars into silver coins. www.convert2silver.com


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
  •