|
-
Dec 18th, 2003, 01:57 PM
#1
Thread Starter
Frenzied Member
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?
-
Dec 18th, 2003, 02:17 PM
#2
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.
-
Dec 18th, 2003, 02:19 PM
#3
Thread Starter
Frenzied Member
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.
-
Dec 18th, 2003, 02:35 PM
#4
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?
-
Dec 18th, 2003, 03:10 PM
#5
Thread Starter
Frenzied Member
With a 0, but yes Thank you!!!!
-
Dec 18th, 2003, 03:17 PM
#6
-
Dec 19th, 2003, 12:00 PM
#7
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.
-
Dec 19th, 2003, 12:35 PM
#8
Thread Starter
Frenzied Member
Yeah, someone else in another forum suggested the alias idea too. I hadn't thought about that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|