CodingMySQL sadness

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  steve      
38315.13 In reply to 38315.1 
Your tags should be in a separate table, with a cross-table between the two. I haven't tested this (and don't have the means to ATM), so would likely need 'tweaking' (possibly needs JOIN LEFT):

TABLE 1
code:
ImageID	Image
1	cat.jpg
2	mouse.jpg
3	hamster.jpg
4	dog.jpg

TABLE 2
code:
TagID	Tag
1	nice
2	bitey
3	fuzzy

TABLE 3
code:
ImageID	TagID
1	1
4	1
2	2
3	2
1	3
2	3
3	3
4	3

SQL (pronounced 'sequel')
sql code:
SELECT t1.* FROM images t1
JOIN crosstab t2 ON t1.ImageID=t2.ImageID
JOIN tags t3 ON t2.TagID=t3.TagID
WHERE t3.Tag='fuzzy' AND t3.Tag='bitey';

bastard by name, bastard by nature

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  99% of gargoyles look like (MR_BASTARD)     
38315.14 In reply to 38315.13 
t3.Tag can't be two things at once.
0/0
 Reply   Quote More 

 From:  99% of gargoyles look like (MR_BASTARD)  
 To:  Peter (BOUGHTONP)     
38315.15 In reply to 38315.14 

Maybe the 'AND' should be 'OR'
<shrug>

bastard by name, bastard by nature

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  99% of gargoyles look like (MR_BASTARD)     
38315.16 In reply to 38315.15 
And then he'd need the group by/having again, to restrict it to items with both.
0/0
 Reply   Quote More 

 From:  steve   
 To:  99% of gargoyles look like (MR_BASTARD)     
38315.17 In reply to 38315.13 
I realised it'd be better to have the tags work like that, but like I said - it's a very small-scale script and there are benefits to doing it this way (when the last image tagged as something has it's tag removed, that option vanishes altogether.etc).

0/0
 Reply   Quote More 

Reply to All    
 

1–17

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats