Database Query Help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
DonPatricio91
Forum Newbie
Posts: 18
Joined: Tue Dec 11, 2007 7:32 pm

Database Query Help

Post by DonPatricio91 »

HI,

I got a Database with a Table. The table consists of 2 columns. One named first, the other named second. In these Databases values get inserted.
Specifically, values of users get inserted, cause my whole project consists of a type of community.
Now, I got a Cookie:

Code: Select all

$username;
which tells me which user is logged in. I now want to select all the values in the table from the 2 columns which have the same value. Each value, in the table) has one other value and I want to be able to select exactly these values:

A little demonstration of what I mean:

Database:

first second

Patrick Philip
Danny Thomas
Alex Patrick
Timmy Patrick
Patrick Moritz


As you can see I have 4 Patrick's in my database. And now I would like to be able to select the underlined values and put them on my php page in the format value, value etc.

I couldn't think of any possible to way to do this, but I also just started with programming. So, I would really appreciate somebody helping me out here. Thanks a lot guys ..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Can you post your table structure?
DonPatricio91
Forum Newbie
Posts: 18
Joined: Tue Dec 11, 2007 7:32 pm

Post by DonPatricio91 »

the structure is exactly as I mentioned in my first post.

2 columns one named: first, other: second
RobertPaul
Forum Contributor
Posts: 122
Joined: Sun Sep 18, 2005 8:54 pm
Location: OCNY

Post by RobertPaul »

You could do something like

Code: Select all

SELECT first, second FROM your_table WHERE user1 = 'patrick' OR user2 = 'patrick'
and then as you're iterating through the results just ignore any 'patrick' value.
DonPatricio91
Forum Newbie
Posts: 18
Joined: Tue Dec 11, 2007 7:32 pm

Post by DonPatricio91 »

didn't try it yet, but that'll work i think. thanks for helping
Post Reply