How do I subscribe to receive blog comments to my e-mail?
find a value in entire table...
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > PHP web-programming > find a value in entire table... 6 April 2005 18:03:35

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

find a value in entire table...

Tristan Pretty 6 April 2005 18:03:35
 I need to search an entire table for a value, and then report back what
field it was found in... how on earth do I do that?
I've a list of departments, as field names.
whenever a user interacts with that Dpet, I wanna add thier id No to the
appropriate field.
so I'll be left with a table that looks like this:

===================­=============
| Accounts | HR | Support | Marketing |
-------------------­--------------------­-----------------
| 23 | | | |
| | 17 | | |
| | | 17 | |
| 19 | | | |
| | | | 4 |
===================­=============

So User 17 has dealt with HR and Support, and user 23 has dealt with only
Accounts.
So I wanna input an user ID no, and then get told what Dpets have been
accessed...

I need to learn this, as I know it's simple, but I've never had to do it
before!

Tris....

--
PHP Database Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Martin Norland 6 April 2005 17:51:57 permanent link ]
 Tristan.Pretty@risk.­sungard.com wrote:> I need to search an entire table for a value, and then report back what > field it was found in... how on earth do I do that?> I've a list of departments, as field names.> whenever a user interacts with that Dpet, I wanna add thier id No to the > appropriate field.
[snip]> So I wanna input an user ID no, and then get told what Dpets have been > accessed...>
I need to learn this, as I know it's simple, but I've never had to do it > before!

You'll be better off storing a single row for each user/department
interaction. In fact, break them straight out into id's and just have
it as a linking table

user_department_int­eractions
| user_id | department_id |

then have a table for the departments information

departments
| department_id | department_name | more fields... |

a simple join in your query will tell you the department name

select distinct department_name from user_department_int­eractions where
user_id=3 AND user_department_int­eractions.department­_id =
departments.departm­ent_id;

the above will return a list of department names that user_id 3
interacted with. Whenever they interact with a department you just
insert a single row into the user_department_int­eractions table, if you
only ever want to store whether they interacted at all, you can set
constraints and catch the error on insert, or search before inserting.

cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International
Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

--
PHP Database Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Tristan Pretty 6 April 2005 17:54:32 permanent link ]
 that's a fine idea!
I'll hve a play...

Cheers...





Martin Norland <martin.norland@stj­ude.org>
06/04/2005 14:51
Please respond to
php-db@lists.php.ne­t


To
php-db@lists.php.ne­t
cc

Subject
Re: [PHP-DB] find a value in entire table...






Tristan.Pretty@risk­.sungard.com wrote:> I need to search an entire table for a value, and then report back what > field it was found in... how on earth do I do that?> I've a list of departments, as field names.> whenever a user interacts with that Dpet, I wanna add thier id No to the
appropriate field.
[snip]> So I wanna input an user ID no, and then get told what Dpets have been > accessed...>
I need to learn this, as I know it's simple, but I've never had to do it
before!

You'll be better off storing a single row for each user/department
interaction. In fact, break them straight out into id's and just have
it as a linking table

user_department_int­eractions
| user_id | department_id |

then have a table for the departments information

departments
| department_id | department_name | more fields... |

a simple join in your query will tell you the department name

select distinct department_name from user_department_int­eractions where
user_id=3 AND user_department_int­eractions.department­_id =
departments.departm­ent_id;

the above will return a list of department names that user_id 3
interacted with. Whenever they interact with a department you just
insert a single row into the user_department_int­eractions table, if you
only ever want to store whether they interacted at all, you can set
constraints and catch the error on insert, or search before inserting.

cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International
Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

--
PHP Database Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Jos Juffermans 6 April 2005 18:03:35 permanent link ]
 Hi,

You could do something like this:


SELECT 'Accounts' as department, Accounts as id FROM mytable WHERE Accounts
IS NOT NULL
UNION ALL
SELECT 'Human Resources' as department, HR as id FROM mytable WHERE HR IS
NOT NULL
UNION ALL
SELECT 'Support' as department, Support as id FROM mytable WHERE Support IS
NOT NULL
UNION ALL
SELECT 'Marketing' as department, Marketing as id FROM mytable WHERE
Marketing IS NOT NULL


Replace "mytable" with your tablename.

I know it works on Oracle and I've just tested in on MySql and that works
good too. The query above returned this:

department | id
----------------|--­--
Accounts | 23
Accounts | 19
Human Resources | 17
Support | 17
Marketing | 4

Jos


-----Original Message-----
From: Tristan.Pretty@risk­.sungard.com
[mailto:Tristan.Pretty@risk.sungard.com]
Sent: 06 April 2005 14:52
To: php-db@lists.php.ne­t
Subject: [PHP-DB] find a value in entire table...


I need to search an entire table for a value, and then report back what
field it was found in... how on earth do I do that?
I've a list of departments, as field names.
whenever a user interacts with that Dpet, I wanna add thier id No to the
appropriate field.
so I'll be left with a table that looks like this:

===================­=============
| Accounts | HR | Support | Marketing |
-------------------­--------------------­-----------------
| 23 | | | |
| | 17 | | |
| | | 17 | |
| 19 | | | |
| | | | 4 |
===================­=============

So User 17 has dealt with HR and Support, and user 23 has dealt with only
Accounts.
So I wanna input an user ID no, and then get told what Dpets have been
accessed...

I need to learn this, as I know it's simple, but I've never had to do it
before!

Tris....

--
PHP Database Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php

--
PHP Database Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > PHP web-programming > find a value in entire table... 6 April 2005 18:03:35

see also:
[feature] create a fields.inc for…
[feature] Mirror mailing lists as…
[task] Drupal Install System
пройди тесты:
Do you really know yourself?
see also:
How to make a Christmas photo…
Unable to Print Embedded Pictures in…
:-$

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .