Ok, I hardly consider myself a programer, or a DBA type guy, so please bear with me. 
I need to know if I\'m going about something the right way, and I don\'t know if it\'s a PHP thing, or a SQL thing.
Little background:
What I am doing, is making a php front end to a mssql database. I work for a company that has 1100+ locations throughout the world, each one of these locations is backed up on a nightly basis, and the success or failure of that backup is logged into an mssql database. I want to query the database to find out how many servers have been backed up on a given day, and the status of that back up. No problem. I\'ve accomplished this.
What I need to do now is, query the database to find the last good backup of a given server (if it\'s a fialure). There is no last good backup field in the database, so I have to search through the database until I come accorss a \"success\" backup and use the date.
I\'ve gotten this to work, but it takes FOREVER. So I don\'t know if there is something that I can do with the SQL or the PHP that will speed this up.
Here is a snippet of the code I wrote..
while( $row = mssql_fetch_row( $cur ))
{
$server_name = $row[1];
$sf_flag = $row[3];
//I\'m just using the first record that comes up as the last good backup.
$lgb_cur = mssql_query(\"SELECT s_f_flag, sname, date FROM $table_save_group WHERE s_f_flag =\'s\' AND sname = \'$server_name\' ORDER by date desc\", $cnx);
$lgb_row = mssql_fetch_row($lgb_cur);
$lgb_date = $lgb_row[2];
}
Hope someone can make sense of that

I need to know if I\'m going about something the right way, and I don\'t know if it\'s a PHP thing, or a SQL thing.
Little background:
What I am doing, is making a php front end to a mssql database. I work for a company that has 1100+ locations throughout the world, each one of these locations is backed up on a nightly basis, and the success or failure of that backup is logged into an mssql database. I want to query the database to find out how many servers have been backed up on a given day, and the status of that back up. No problem. I\'ve accomplished this.
What I need to do now is, query the database to find the last good backup of a given server (if it\'s a fialure). There is no last good backup field in the database, so I have to search through the database until I come accorss a \"success\" backup and use the date.
I\'ve gotten this to work, but it takes FOREVER. So I don\'t know if there is something that I can do with the SQL or the PHP that will speed this up.
Here is a snippet of the code I wrote..
while( $row = mssql_fetch_row( $cur ))
{
$server_name = $row[1];
$sf_flag = $row[3];
//I\'m just using the first record that comes up as the last good backup.
$lgb_cur = mssql_query(\"SELECT s_f_flag, sname, date FROM $table_save_group WHERE s_f_flag =\'s\' AND sname = \'$server_name\' ORDER by date desc\", $cnx);
$lgb_row = mssql_fetch_row($lgb_cur);
$lgb_date = $lgb_row[2];
}
Hope someone can make sense of that
