Page 1 of 1

Database Query Help

Posted: Fri Dec 14, 2007 9:48 pm
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 ..

Posted: Fri Dec 14, 2007 10:23 pm
by John Cartwright
Can you post your table structure?

Posted: Fri Dec 14, 2007 10:46 pm
by DonPatricio91
the structure is exactly as I mentioned in my first post.

2 columns one named: first, other: second

Posted: Fri Dec 14, 2007 10:49 pm
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.

Posted: Fri Dec 14, 2007 10:54 pm
by DonPatricio91
didn't try it yet, but that'll work i think. thanks for helping