php code to compare sql entrys

Associate
Joined
18 Oct 2002
Posts
710
Location
Somerset
I am reading a very good tutorial on php and sql but what i am trying to comile while reading it has jumped ahead of the tutorial a little so was hoping i could find some help here to keep things moving while i read.

i have a sql database, the database has 2 tables,

table 1 has all its info read out and inserted into a table on the page,

i need to compare the contents of table 1 column 5 to the contents of table 2 column 1 for each row of table 1,then return the contents of table 2 column 2 for each row

I have not not to any part on comparing table/column contents yet, i assume it is possible to do this some how?

Thanks
 
I think what you are looking for is INNER JOIN, presuming it's mySQL.

SELECT table1.column5, table2.column2 FROM table1 INNER JOIN table2 ON table1.column1=table2.column5

Get that into an array using mysql_fetch_assoc and print_r() the array to see exactly what the query gives you :)

Note that I may have messed up or made a massive oversight in the above query - in which case you need to figure out how to write it yourself, 'cos I can't be bothered to test it :p:D
 
Thanks for the replies, i will give that a go,

It is actually the tizag tutorials i am making my way through, so eventually i will get to that part :)
 
hehe, i learnt from experience it's generally a bad idea to skip sections of stepped tutorials like that - no matter how trivial you think it is - i've missed learning about some useful/interesting techniques that way!
 
hehe, i learnt from experience it's generally a bad idea to skip sections of stepped tutorials like that - no matter how trivial you think it is - i've missed learning about some useful/interesting techniques that way!


Im not skipping any thing, it will all get read and done,

I just want to try and get this that i am currently working on done and i need to be able to do that part, everything else i am currently doing with this project i have covered in the tutorial,

I am finding the tutorials on that site very helpful.
 
You may have already noticed but the sql should be...

Code:
SELECT table1.column5, table2.column2 
FROM table1 INNER JOIN table2 ON table1.column5=table2.column2

Furnace got all mixed up with the join columns :D
 
Thanks Mark,

Yes i have noticed, took the details Furnace gave and went looking at the tizag pages to find the section on it, had a working join running and doing what i wanted, then changed what i wanted to do :)
 
Back
Top Bottom