Board index   FAQ   Search  
Register  Login
Board index php forum :: Database phpMyAdmin

format

How to use phpmyadmin.... phpmyadmin related arguments. Even phpMyAdmin issues

Moderators: macek, egami, gesf

format

Postby maktub » Mon Jun 07, 2004 9:11 am

Can anybody tell me what is the propose for a select like this:

SELECT *,format - 1 as bol_format
FROM ...

I don't know the meaning of 'format'.

Thanks.
maktub
 

Re: format

Postby swirlee » Mon Jun 07, 2004 10:41 am

maktub wrote:SELECT *,format - 1 as bol_format
FROM ...


Please take a look at the documentation for SELECT Syntax. It will tell you that everything after SELECT (and certain keywords) is part of the select_expression, which describes what data to return. Most often, this is just a list of columns. You can use * to designate all columns, but this is not a recommended approach. In the example you presented, after the *, it has 'format - 1 AS bol_format'. 'format - 1' is just a mathematical expression which says "take the value in the column named 'format' and subtract one from it. The AS keyword just renames the value when it is returned, so in this case instead of being named 'format - 1', the column will be named 'bol_format' in the output. Here's an example to demonstrate:

Code: Select all
SELECT format FROM table1;
+--------+
| format |
+--------+
| 5      |
+--------+

SELECT format - 1 FROM table1;
+------------+
| format - 1 |
+------------+
| 4          |
+------------+

SELECT format - 1 AS bol_format FROM table1;
+------------+
| bol_format |
+------------+
| 4          |
+------------+
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

format

Postby maktub » Mon Jun 07, 2004 11:47 pm

Thanks, but format isn't the name of any column data so I don't know if it's a function or something like that for MySQL.
maktub
 

format

Postby maktub » Mon Jun 07, 2004 11:50 pm

The table is this:

CREATE TABLE shoutbox_demo (
id mediumint(8) unsigned NOT NULL auto_increment,
channel varchar(25) NOT NULL default '',
screenname varchar(25) NOT NULL default 'anonymous',
remote_addr varchar(15) NOT NULL default '',
user_agent varchar(255) NOT NULL default '',
timestamp int(11) NOT NULL default '0',
message text NOT NULL,
PRIMARY KEY (id),
KEY channel (channel)
) TYPE=MyISAM COMMENT='PHP ShoutBox';
maktub
 

Postby swirlee » Tue Jun 08, 2004 11:32 am

'format' is not a MySQL keyword, so unless it's the name of a column, having it anywhere in your SELECT statement (except quoted, of course) will cause an error.

Maybe if you could post the whole query, we could get more insight into this.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to phpMyAdmin

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.