SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old July 28th, 2006, 09:38 AM
QrycheOM QrycheOM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 6 QrycheOM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 37 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old July 28th, 2006, 10:36 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
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

Reply With Quote
  #3  
Old July 28th, 2006, 11:04 AM
QrycheOM QrycheOM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 6 QrycheOM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 37 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
What does "fb" stand for?
You may want to consider breaking that data into two different tables.


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

Reply With Quote
  #4  
Old July 28th, 2006, 01:26 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
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 |

Reply With Quote
  #5  
Old July 28th, 2006, 01:50 PM
QrycheOM QrycheOM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 6 QrycheOM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 37 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
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 |


=============================================
(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

Reply With Quote
  #6  
Old July 28th, 2006, 06:13 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
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"


Reply With Quote
  #7  
Old July 28th, 2006, 07:59 PM
QrycheOM QrycheOM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 6 QrycheOM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 37 sec
Reputation Power: 0
Quote:
Originally Posted by Madpawn
MadCowDzz is correct; this data should be broken up into separate tables. It'll scale just fine.


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

Reply With Quote
  #8  
Old July 28th, 2006, 08:04 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
MadCowDzz's example is perfect; I don't really have anything to add to it.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > QUERY Question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway