Problem with sql query with to many 'and' conditions

Discussion in 'PHP' started by mwbell0815, Feb 27, 2008.

  1. #1
    Hello

    I am having a real issue with a select statement. The query works just fine in toad but i cannot get it to work through php. Here is what I have:

    //getting info for items that match search screen
    $sql = "select a.tdm_id, a.revision, a.file_name, a.file_type, a.object_id, a.class_id ";
    $sql .= "from tn_documentation a ";
    $sql .= "where tdm_id like '$PartNumber' ";
    $sql .= "and state=3 ";
    $sql .= "and class_id <> 1023 ";
    $sql .= "and class_id <> 709 ";
    if (isset($_GET['chkLatestRev'])) { $sql .= "and creation_date=(select max(creation_date) from tn_documentation where tdm_id=a.tdm_id) "; }
    $sql .= "order by tdm_id asc";

    $stid = oci_parse($c, $sql);

    oci_execute($stid, OCI_DEFAULT);
    if (!oci_fetch_object($stid)) {
    $ERROR++;
    } else {

    while ($myrow = oci_fetch_array ($stid, OCI_NUM)) {
    blah blah
    }

    if I take out all but one of the and conditions it works fine. Im stumped...
    Has anyone ran across this before..??

    thanks
    Mike
     
    mwbell0815, Feb 27, 2008 IP
  2. mwbell0815

    mwbell0815 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    OK..I figured it out...it was actually the error checking not the query...

    problem code:
    oci_execute($stid, OCI_DEFAULT);
    if (!oci_fetch_object($stid)) {
    $ERROR++;
    } else {
     
    mwbell0815, Feb 27, 2008 IP
  3. quicksolutions

    quicksolutions Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Another easy way to figure out the sql query problems.echo the query,copy it and execute in the db it will explain the exact problem.
     
    quicksolutions, Feb 28, 2008 IP