Jump to content

how to select all values from a mysql table except one specific field


sonill

Recommended Posts

$query = mysql_query("SELECT * FROM `table`"); //assuming said table has only one row of information
$assoc_array = mysql_fetch_assoc($query);

foreach($assoc_array as $key=>$value){
     if($key != "the_one_specific_field"){
          echo $value;
     }
}

If you have more than one row -

$sql = "SELECT column1, column2 FROM table";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
     echo $row['column1'];
     echo $row['column2'];
}

 

So basically, you just change column1, column2 to column names. Just put them all except that one column.

 

So if you have columns -

id

name

password

date

status

 

And you want to display everything except password, you would do this -

$sql = "SELECT id, name, date, status FROM table";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
     echo $row['id'] . '<br />';
     echo $row['name'] . '<br />';
     echo $row['date'] . '<br />';
     echo $row['status'];
}

 

Like that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.