sonill Posted May 18, 2009 Share Posted May 18, 2009 i have a situation in my php code where i have to select all the value from the table and echo it in the web page except one specific field. is there any way to do that? i hope there is... Link to comment https://forums.phpfreaks.com/topic/158541-how-to-select-all-values-from-a-mysql-table-except-one-specific-field/ Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 $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; } } Link to comment https://forums.phpfreaks.com/topic/158541-how-to-select-all-values-from-a-mysql-table-except-one-specific-field/#findComment-836192 Share on other sites More sharing options...
Ken2k7 Posted May 18, 2009 Share Posted May 18, 2009 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. Link to comment https://forums.phpfreaks.com/topic/158541-how-to-select-all-values-from-a-mysql-table-except-one-specific-field/#findComment-836194 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.