Results 1 to 5 of 5

Thread: What is wrong with this syntax?

  1. #1
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76

    What is wrong with this syntax?

    here's my php code, but its not doing anything. Is the syntax right?
    (especially on the select statement)

    $sql="Select * From COMPANY As C Inner Join ACTIVITY AS A On A.C_NUMBER = C.C_NUMBER
    Where C.A_DATE = '$date'";
    $result = mysql_query($sql);
    //$numofrows = mysql_num_rows($result);
    echo $result;
    THANKS

  2. #2
    Join Date
    Feb 2003
    Posts
    1,048
    Are you getting an error? If so, what?

  3. #3
    Join Date
    Jun 2005
    Location
    coronado
    Posts
    76
    No, I'm not getting an error, (thanks to you)
    Ok, I shortened it a lot, Here's my php code.
    <?php
    $hostname = "10.0.0.127";
    $username = "*";
    $password = "blues7";
    $database = "test";
    $connection = mysql_connect($hostname , $username , $password)
    or die("cannot make connection");
    $db = mysql_selectdb($database , $connection)
    or die("cannot find database");
    $sql="Select * From COMPANY As C Inner Join ACTIVITY AS A On A.C_NUMBER = C.C_ID Where A.A_DATE ='".$date."'";
    $result = mysql_query($sql) or die(mysql_error());
    $numofrows = mysql_num_rows($result);
    ?>
    heres some more to display the results of the query in a table..
    while ($row = mysql_fetch_object($result)){
    print "<TD>".$row->C_NAME."</TD>";
    print "<TD>".$row->C_CITY.", ".$row->C_STATE."</TD>";
    print "<TD>".$row->C_DESC."</TD>";
    print "<TD>".$row->RATIONALE."</TD>";
    print "<td>".$row->contact_NAME."</TD>";
    print "<td>".$row->contact_PHONE."</td>";
    print "<TD>".$row->A_DATE."</TD>";
    print "<TD>".$row->A_DESC."</TD>";
    print "<td>".$row->NEXT."</TD>";
    print "<td>".$row->MEDIVAS."</td>";
    print "</TR>\n";
    }

    for some reason, it returns only the results where C_NUMBER is equal in the ACTIVITY table, not where A_DATEs' are equal. Shouldn't the query return only instances where A_DATE's are equal.

  4. #4
    Join Date
    Feb 2003
    Posts
    1,048
    Is there more than 1 A_Date field?

    The query is written to return records where C_Number = C_ID and A_Date = $date. Is this what you want to be returned?

  5. #5
    Join Date
    Jul 2003
    Posts
    421
    Hi,
    for web database, one way to debug is test the pure sql code on sql enviroment, then you would found the mistake is on sql or php.

    why don't try?
    good luck!
    ________
    Girlfriend pic
    Last edited by sql; 03-06-2011 at 01:41 AM.

Posting Permissions

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