Q:

How to choose row name in mysql table from local variable in PHP code?

Is there a way to choose row name in mysql table from a variable in Php code? For example, instead of SELECT email, I want SELECT email_2 based on my if statement like this:
$value == "";
if(true){
$value = email
SELECT $value from....
else{
$value = email_2
SELECT $value from....
}

This is my php code:
    $stmt = $conn->prepare("SELECT email from account_data_base WHERE test = ?");

$stmt->bind_param("s", $test);

A:

You could use a variable to select the column you want. You cannot use the statement on column names.
$test = 'your_value';
$column = 'email'; // column by default

if ($your_condition_is_true) {
    $column = 'email_2';
}

$stmt = $conn->prepare("SELECT $column FROM account_data_base WHERE test = ?");
$stmt->bind_param("s", $test);

