Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MYSQL: Refer to column name when name is number

Status
Not open for further replies.

chromonium

Programmer
Jun 4, 2002
36
FR
Hello everyone.

When querying a MYSQL DB with PHP, how can you query a column ie [WHERE 1='test'] when the column/field name is itself a number?

Thanks very much

Many Regards

adam

 
You might try WHERE `1` = 'test' (backticks around the name of the column).

But using numbers for column names is a very bad idea. The programmers allow you to use descriptive names for a column to make your code easier to understand.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Yeah thanks...

I've now abandoned that system, instead calling them q1, q2 etc instead of 1, 2 etc, then stripping string of 'q' at other end.

regards

adam
 
You might want to rethink your database schema.

Tables consisting of repeated columns like "x1", "x2", etc, generally contain a single class of data with multiple values. Data like that is better stored "vertically" in a related table rather than "horizontally" in a single table.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top