简体   繁体   中英

i want select name form one table and display in my page

SELECT name from tbl_gallery, tbl_gallery_category where 'name' = 'gallery-cat-id';

I have two tables one for category and second for saving images with category name my query is here Then executing thien shows MySQ L returned an empty result set (ie zero rows). (Query took 0.0007 seconds.)

Remove single quotes in name instead of 'name' read when to use single quotes, double quotes, and backticks

If you put single quotes on table or column name, they are treated as string so don't put.

SELECT `name` 
FROM tbl_gallery 
JOIN tbl_gallery_category ON tbl_gallery.name = tbl_gallery_category.gallery-cat-id;

Note :

where 'name' = 'gallery-cat-id';   

above where condition is always false only. Because your just comparing 'name' is equal to 'gallery-cat-id' so that it's false .

Don't use quotes on table or column names.

SELECT name 
from tbl_gallery
join tbl_gallery_category on tbl_gallery.name = tbl_gallery_category.`gallery-cat-id`

If you need to escape a column name then use backticks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM