|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
QUERY Question
Hi,
I have a quick 2 part query question. My DB has a MySQL table (tbFbrcs) setup like this. ie., ============================================= fbId | fbH4 | fb51 | fb64 | fb70 | fb67 -------------------------------------- 23 | 1 | 0 | 1 | 1 | 0 44 | 0 | 0 | 1 | 1 | 0 ============================================= Is there a way to select fbId 23 and only the fields in that row that equal 1. SELECT * FROM tbFbrcs WHERE fbId = '23' AND rest = '1' I want to use this format because I will eventually add more fields. Second question: If above is possible, can the field names selected be shown? ie., when fbId = 23 is selected, fbH4,fb64,fb70 Thank you, QrycheOM |
|
#2
|
||||
|
||||
|
What does "fb" stand for?
You may want to consider breaking that data into two different tables.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#3
|
|||
|
|||
|
Quote:
consider fbH4,fb51,fb64,fb70,fb67 images fbId is either associated(1) or not (0) I want to query only the images associated with #23 QrycheOM |
|
#4
|
||||
|
||||
|
What are these images associated with?
I can't quite figure out the logic and seemingly random field names. =) Might want to consider some database normalization. If you were to separate it into a couple tables you could run more acurate queries. Something ------------ | ID | value | Images ------------ | ID | value | Something_Images [a bridge table because it sounds like a many to many relationship] -------------- | image_id | something_id | |
|
#5
|
|||
|
|||
|
Quote:
============================================= (fbH4,fb51,fb64,fb70,fb67) are the field names of the table and fbId is the item associated with the images. To show that they are associated or not enum('1', '0') So, Item #23 is associated with(from above) fbH4 | fb64 | fb70 23 | 1 | 0 | 1 | 1 | 0 Item #44 is only associated with fb64 | fb70 using a list or association(PHP or Perl) when I query row fbId=23: ($iid,$ih4,$i51,$i64,$i70,$i67) = mysql_fetch_row ( $cksql ); gives me (23 , 1 , 0 , 1 , 1 , 0) I could put $ih4,$i51,$i64,$i70,$i67 thru a loop to weed out the zeros but was wondering if there was an easier approach. Having a sep table wouldn't scale nice. *The field patterns come from the table associated with it: Table = tbFbrcs Fields of that table = fbH4, fb51 (images H4.jpg, 51.jpg, etc) when writing code after the caffeine drip stops it helps to stay on track. QrycheOM |
|
#6
|
|||
|
|||
|
MadCowDzz is correct; this data should be broken up into separate tables. It'll scale just fine.
__________________
"A pawn is the most important piece on the chessboard -- to a pawn" |
|
#7
|
|||
|
|||
|
Quote:
Examples are better then just stating. I want to avoid: ================================================== =========================== fbId|fbImg1|fbImg2|fbImg3|fbImg4|fbImg5|fbImg6|fbI mg7|fbImg8|fbImg9|fbImg10 23|Coco-67.jpg|PinaColada-H4.jpg|Khol-51.jpg|Mosaic-64.jpg|Deco-70.jpg|NULL|NULL|NULL|NULL|NULL 44|Coco-67.jpg|PinaColada-H4.jpg|Khol-51.jpg|Mosaic-64.jpg|Deco-70.jpg|NULL|NULL|NULL|NULL|NULL 10|Coco-67.jpg|PinaColada-H4.jpg|NULL|Mosaic-64.jpg|NULL|NULL|NULL|NULL|NULL|NULL ================================================== =========================== and use the fields |
|
#8
|
|||
|
|||
|
MadCowDzz's example is perfect; I don't really have anything to add to it.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > QUERY Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|