Welcome to WebmasterWorld Guest from 220.127.116.11
Forum Moderators: open
I used $query="ALTER TABLE news ADD align1 varchar(10) NOT NULL";
To add three columns. But they are not working; the values are always empty.
I tried using SHOW to dump the table.
All I want is to see the column names in a table.
But I can't figgure out how to hash the result and display it, without already KNOWING whats in there?
$show = "SHOW COLUMNS FROM news";
From MySQL's site:
SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE 'pattern']
SHOW COLUMNS lists the columns in a given table. If the column types differ from what you expect them to be based on your CREATE TABLE statement, note that MySQL sometimes changes column types when you create or alter a table. The conditions for which this occurs are described in Section 18.104.22.168, “Silent Column Specification Changes”.
The FULL keyword can be used from MySQL 3.23.32 on. It causes the output to include the privileges you have for each column. As of MySQL 4.1, FULL also causes any per-column comments to be displayed.
You can use db_name.tbl_name as an alternative to the tbl_name FROM db_name syntax. These two statements are equivalent:
mysql> SHOW COLUMNS FROM mytable FROM mydb;
mysql> SHOW COLUMNS FROM mydb.mytable;
SHOW FIELDS is a synonym for SHOW COLUMNS. You can also list a table's columns with the mysqlshow db_name tbl_name command.
The DESCRIBE statement provides information similar to SHOW COLUMNS. See Section 13.3.1, “DESCRIBE Syntax (Get Information About Columns)”.
$query = "SHOW COLUMNS FROM news";
print "There are $num_results columns.<br>";
$row = mysql_fetch_array($result);
for ($i = 0; $i < $num_results; $i++)
print "Field " . $row[$i] . " exists.<br>";
And this is the results. It did not give me the names of the columns :( But rather, something else.
There are 11 columns.
Field id exists.
Field int(6) exists.
Field PRI exists.
Field auto_increment exists.
I got it with the DESC command. The new columns are there.
So why does it not work?
I can set the value for the column. Value is correct type.
Then when I read the value, its blank. Like it never set.
When you ADD columns, does it add them for already existing entries? Maybe it does not, and thats why it wont take?