Is it possible in SQL SELECT * FROM table WHERE column 1 = something, not column_name = something

I would like SELECT * FROM tablewhere the first column is equal to a variable. He suggested that I do not know the name of the column.

I know I can do something like

SELECT * FROM table WHERE column_id = 1 

But I can not compare the data.

How can i do this?

I found some solution with T-SQL, but that doesn't interest me.

To be more precise:

I am developing an admin panel on my website where the super administrator can directly modify the database. To do this, I can select a table and edit this table. But for this I use only a PHP script that shows all the tables, we can select one and the script show all the rows in the selected table. After that, you select the line and you are redirected to the page where there is a problem. This page can accept any table with only one row, so I want the SELECTdata contained in this row.

:
.
.
() 1 , .
selecto http://imageshack.us/g/135/selecto.png

:

: : ,

 $query="SELECT * FROM ".$_POST['table']."";
    $result=mysql_query($query);

: ( )

while($fields=mysql_fetch_array($result))
    {
        $col =  mysql_field_name($result,0);
        $nb++;
    }

-: where $col = id

$sql = "SELECT * FROM ".$_POST['table']." WHERE ".$col."=".$_GET['idRow']."";
$result1=mysql_query($sql);
+5
3

, , :

SELECT *
FROM (
  SELECT null x1, null x2, ..., null xn
  WHERE 1 = 0
  UNION ALL
  SELECT * FROM my_table
) t
WHERE t.x1 = something

, MySQL, "" , . PostgreSQL :

SELECT * FROM my_table t(x) WHERE x = something

... information_schema:

SELECT column_name
FROM information_schema.columns
WHERE table_name = :my_table
AND ordinal_position = 1

SQL-

, . EVER:

$query="SELECT * FROM ".$_POST['table']."";

SQL. , , script kiddie , .

, . , $_POST , SQL, .

+1

PHP - :

$col = 'users';
mysql_query("SELECT * FROM table WHERE $col = $something");
0

I think you can use SHOW CREATE TABLE table_nameto retrieve the table schema. After that, you should know each column.

0
source

All Articles