assume that we have an mysql table with some rows. We want to check being of a specific records which for instance, its 'index'=0 . By php , after make a query like "SELECT * from My_table" we always use the commands like mysql_fetch_array and then use this structure:
while ( $row = mysql_fetch_array($sql_result) )
{
if ( $row['index'] == 0 )
return true;
}
But this method obtain time as O(n) . How can optimize this algorithm to O(1)? and then write whole of the row that we've searched for it?
Note that I want to find the specific row by php not by sql like SELECT ... WHERE index=1. In the other words I want to get the row from the array which yields from mysql_fetch_array.