you could do something like this...
$q = '';
$s = '';
$table = 'tablename';
$fields = mysql_list_fields($dbn, $table);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++)
{
$name = mysql_field_name($fields, $i);
$s .= "$name, ";
$q .= "$name=4 ";
}
$query = "SELECT $s FROM $table WHERE $q";
$results = mysql_query($results);
....
If I'm not mistaken, this should return a SINGLE row where those fields are all equal to 4, if thats not what you are looking for, remove the "WHERE $q" and then loop through the ROW for $key/$val sets that equal 4 using something like
while(list($key, $val) = mysql_fetch_array($results, MYSQL_ASSOC))
{
if ($val == 4) { do this with $key; }
}
Hopefully this isnt too messy of a solution?
fyi, the code up top is from a SQL management type page I wrote that works with any fields/tables in a database, still growing, but working so great for what it does for now 🙂