Results 1 to 8 of 8

Thread: Query Results

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Query Results

    I'm using the following:
    PHP Code:
     $s mssql_connect($myServer$myUser$myPass
    or die(
    "Couldn't connect to SQL Server on $myServer"); 

    $d mssql_select_db($myDB$s
    or die(
    "Couldn't open database $myDB"); 

    $query "SELECT MAX([Revision Date]) "
    $query .= "FROM [Program Revision Level]"

    $result mssql_query($query); 
    $row mssql_fetch_array($result);


    echo 
    $row["Revision Date"];


    echo 
    "<br>Latest Revision Date: "$row["Revision Date"];

    $query "SELECT MAX([Revision Level]) "
    $query .= "FROM [Program Revision Level] "

    $result mssql_query($query); 
    $row mssql_fetch_array($result);

    echo 
    "<br>Latest Revision Level: "$row["Revision Level"]; 
    Both queries should return only 1 value, but I can't seem to figure out how to get that result. I know I'm connected to the DB, I know the field names and DB name is correct. Can someone tell me how to echo a single result from a query?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    does it return multiple results or something? I ask just because you keep saying you want to return just a single result.

    I've never worked with MSSQL before so I guess I really can't help if it's a problem in your query. Does that return anything at all? I was thinking maybe your table names ("Revision Date" and "Revision Level") might be invalid because of the space, but maybe not.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    The query works fine. I can run it from the Query Analyzer against the DB just fine. But when I stick it in PHP it yells at me.

    It only returns 1 value. I just can't seem to figure out how to handle a 1-value result.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Query Results

    PHP Code:
     $s mssql_connect($myServer$myUser$myPass
    or die(
    "Couldn't connect to SQL Server on $myServer"); 
    $d mssql_select_db($myDB$s
    or die(
    "Couldn't open database $myDB"); 

    $query "SELECT MAX([Revision Date]) FROM [Program Revision Level]"

    $result mssql_query($query$s); 
    $row mssql_fetch_row($result);


    echo 
    $row[1]; 
    Something like that?

  5. #5

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    With a 0, but yes Thank you!!!!

    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    For the original, I can only speak from my experience with MySQL, but I believe it is that you use the wrong name to retrieve from the result array.
    Instead of
    echo $row["Revision Date"];
    try
    echo $row["MAX([Revision Date])"];
    or easier, use an AS in the SQL query to define a shorter name.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Yeah, someone else in another forum suggested the alias idea too. I hadn't thought about that.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

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



Click Here to Expand Forum to Full Width