-
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?
-
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.
-
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.
-
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?
-
With a 0, but yes :D Thank you!!!!
:wave:
-
-
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.
-
Yeah, someone else in another forum suggested the alias idea too. I hadn't thought about that.