miguelmald miguelmald - 10 months ago 21
SQL Question

Exclude a field from a SELECT * FROM $table

I need to exclude a field 'password' from a

SELECT * FROM $table;
is a PHP variable.

Only one of the four posible tables has a 'password' field.

Here is what I have:

function myData($table) {
include "conf.php";
$con = mysqli_connect($host, $user, $password, $db);
$sql = "SELECT * FROM $table;";
$resul = mysqli_query($con, $sql);
return $resul;


Any ideas?

EDIT: This is how I treat the data returned:

$resulFields = myFields($table);
$resulData = myData($table);

while ($fields = mysqli_fetch_array($resulFields, MYSQLI_ASSOC)) {
$field = $fields['Field'];
$header .= "<th>$field</th>";

while ($data_array = mysqli_fetch_array($resulData, MYSQLI_ASSOC) ) {
$body .= "<tr id='$data_array[id]'>";
foreach ($data_array as $data){
$body .= "<td>$data</td>";

Sorry if it's a little bit messy, I'm just starting to learn programming.


Maybe you can do something like this:

function myData($table) {
    include "conf.php";
    $con =   mysqli_connect($host, $user, $password, $db);
    $sql =   "SELECT field1, field2";

    if ($table == "TABLE_WITH_PASSWORD") {
    $sql.=" FROM $table;";

    $resul =  mysqli_query($con, $sql);
    return $resul;