Re: find a value in entire table...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



that's a fine idea!
I'll hve a play...

Cheers...





Martin Norland <martin.norland@xxxxxxxxxx> 
06/04/2005 14:51
Please respond to
php-db@xxxxxxxxxxxxx


To
php-db@xxxxxxxxxxxxx
cc

Subject
Re:  find a value in entire table...






Tristan.Pretty@xxxxxxxxxxxxxxxx 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_interactions
|  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_interactions where 
user_id=3 AND user_department_interactions.department_id = 
departments.department_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_interactions 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



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux