SQL Query Table Name Space
Solved
Giuliano
-
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
Hello everyone,
I would like to make a query to display data from my database on a website. Unfortunately, some table names contain spaces, and I don't know the correct syntax to have the table recognized...
I know what you’re going to say, not to use spaces in table names!! Unfortunately, I didn't create this database and considering its size, it would be impossible for me to rename all the tables...
Could someone help me? My database is Access and I'm programming in PHP on my site.
Thanks in advance!
6 answers
Does anyone have a little idea to help me out? I really don't know what to do anymore... Thank you in advance!
Hi!
I don't think there's a solution to your problem, generally PHP is used to link with a MySQL or similar type database and space is a forbidden character in it. Always try to enclose your table names with ` (Alt GR + 7) but don't get your hopes up too much. In my opinion, you'll need to rename your tables.
I don't think there's a solution to your problem, generally PHP is used to link with a MySQL or similar type database and space is a forbidden character in it. Always try to enclose your table names with ` (Alt GR + 7) but don't get your hopes up too much. In my opinion, you'll need to rename your tables.
Hi, first of all, thank you for your response even if it's not necessarily the one I was expecting... ;o)
Renaming the tables is going to be difficult because there are a lot of them!!! And maybe doing it with another language? Java, ASP?!
I'll look into all of this, and if I can't find another way, I will tackle the task of renaming all my tables...
Thanks anyway!
Renaming the tables is going to be difficult because there are a lot of them!!! And maybe doing it with another language? Java, ASP?!
I'll look into all of this, and if I can't find another way, I will tackle the task of renaming all my tables...
Thanks anyway!
Hi,
Well, it's been a while since you posted your message, but I stumbled upon it by chance because I'm having the same issue but on SQL Server.
For you and others who might have the same problem, the query works fine if you enclose the name of your table in [ ].
So in my case, it looks like this:
select * from [Current Month]
@+
Well, it's been a while since you posted your message, but I stumbled upon it by chance because I'm having the same issue but on SQL Server.
For you and others who might have the same problem, the query works fine if you enclose the name of your table in [ ].
So in my case, it looks like this:
select * from [Current Month]
@+
Otherwise, if you work with PHP and MySQL, simply enclosing the table names with ` in the query is enough for it to work.
See you, Pierre
See you, Pierre
Yes, it is possible to work with MySQL and tables or fields with spaces, even if it's not ideal.
For that, make a small example in PhpMyAdmin with an insertion or a select, it will give you the syntax
example for an insertion:
INSERT INTO `table with space` ( `id` , `width` , `height` , `thickness` , `field name with space`)
VALUES ('$id', '$width', '$height', '$thickness', '$field_name')
Because it is not always easy or even allowed to rename the names of tables or fields, and the person who created the table or the fields did not necessarily do everything as it should be :)
For that, make a small example in PhpMyAdmin with an insertion or a select, it will give you the syntax
example for an insertion:
INSERT INTO `table with space` ( `id` , `width` , `height` , `thickness` , `field name with space`)
VALUES ('$id', '$width', '$height', '$thickness', '$field_name')
Because it is not always easy or even allowed to rename the names of tables or fields, and the person who created the table or the fields did not necessarily do everything as it should be :)
Hello, in the same vein, with PHP and MySQL.
I retrieve document names that will serve as URLs.
The problem is that some document names contain spaces.
So when I retrieve the name and store it in my database, I have: "document name.pdf"
But when I use it in a script to create a link, I simply get: "http://localhost/name"
It is necessary to rename the document to: "document%20name.pdf"
To have the URL: "http://localhost/document%20name.pdf"
My variable $nom contains: "document name.pdf"
But when writing: "http://localhost/`$url`" I get: "http://localhost/%60name"
How can I get a variable that will serve as a URL containing spaces?
Thank you
I retrieve document names that will serve as URLs.
The problem is that some document names contain spaces.
So when I retrieve the name and store it in my database, I have: "document name.pdf"
But when I use it in a script to create a link, I simply get: "http://localhost/name"
It is necessary to rename the document to: "document%20name.pdf"
To have the URL: "http://localhost/document%20name.pdf"
My variable $nom contains: "document name.pdf"
But when writing: "http://localhost/`$url`" I get: "http://localhost/%60name"
How can I get a variable that will serve as a URL containing spaces?
Thank you
Hello. This method doesn't work; putting quotes around it only returns a column of strings containing the name of the initial column. For example, SELECT 'Code secteur' FROM Table returns 'Code secteur' as the column name, then the fields: 'Code secteur', 'Code secteur', 'Code secteur', etc., on each line. However, it is clear that we are looking to obtain the values of the 'Code secteur' column and not its name itself.
If anyone has a solution for this, thank you in advance.
Hello
It is clearly stated that you should not use quotes (apostrophe) or double quotes (quotation marks).. but backquotes... ` (the inverted apostrophe)
And if it's an Access database you should be able to use brackets. [your field] it seems to me