homepage Welcome to WebmasterWorld Guest from 54.243.23.129
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Displaying a MySQL table?
YamahaR1




msg:575040
 3:33 pm on Mar 14, 2005 (gmt 0)

Forgive my ignorance if this is in the wrong place, I didn't see a forum for it.

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?

Please help?

 

gooflox




msg:575041
 4:04 pm on Mar 14, 2005 (gmt 0)

You cannot enforce a "not null" on a new column in a table that already has rows.

$show = "SHOW COLUMNS FROM news";

should work.

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 13.2.6.1, “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)”.


YamahaR1




msg:575042
 4:24 pm on Mar 14, 2005 (gmt 0)

This is what I did.

$query = "SHOW COLUMNS FROM news";
$result=mysql_query($query);

$num_results=mysql_numrows($result);

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 exists.
Field PRI exists.
Field exists.
Field auto_increment exists.
Field exists.
Field exists.
Field exists.
Field exists.
Field exists.

starec




msg:575043
 4:30 pm on Mar 14, 2005 (gmt 0)

check the "desc" command.

desc [table name] (e.g. desc invoice)

YamahaR1




msg:575044
 4:53 pm on Mar 14, 2005 (gmt 0)

OKAY!

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved