ineedhelp Posted January 27, 2007 Share Posted January 27, 2007 Hello.First , sorry for my bad english. Hope you all understand.Ive been fooling around with php and mysql for some time now , but im still learning , and ive run into a problem now.I have 2 tables in my mysql lets call the first A and the second B . now lets say i put name "blargh" in table A , then i want it to check if that name is in table B. something like this:(phpmyadmin)Database_alotofnames (2)-A-BSo that if A "name" = B "name" { do something }{else - tell there is a match}Hope you all understand.Thanks in advance.- The still learning newbie :) Link to comment https://forums.phpfreaks.com/topic/35987-check-if-match-in-2-tables/ Share on other sites More sharing options...
utexas_pjm Posted January 27, 2007 Share Posted January 27, 2007 A simple join should do the trick:[code]<?php//...$name = "foo";$sql = 'SELECT a.name AS a_name, b.name AS b_name FROM a, bWHERE a.name = "'.$name.'"AND a.name = b.name';//..?> [/code]You'll either get nothing, in which case the name does not exist in both tables. Or something, in which case the name does exist in both places.Best,Patrick Link to comment https://forums.phpfreaks.com/topic/35987-check-if-match-in-2-tables/#findComment-170711 Share on other sites More sharing options...
ineedhelp Posted January 27, 2007 Author Share Posted January 27, 2007 Cheers , ill try to see if it works Link to comment https://forums.phpfreaks.com/topic/35987-check-if-match-in-2-tables/#findComment-170713 Share on other sites More sharing options...
ineedhelp Posted January 27, 2007 Author Share Posted January 27, 2007 Hmm i cant seem to get it to work , gah i feel like such a newbie .. wich i am hehThis is what im trying to do : table 1 in mysql is named skabalon , and table 2 is called sideindhold[code]<?php//...$dansknavn = "foo";$sql = 'SELECT skabalon.dansknavn AS skabalon_dansknavn, sideindhold.dansknavn AS sideindhold_dansknavn FROM skabalon, sideindholdWHERE skabalon.dansknavn = "'.$dansknavn.'"AND skabalon.dansknavn = sideindhold.dansknavn';//..?> [/code]Then im trying to make it show by useing [code]<?php do { ?> <?php if ($dansknavn == "foo") { print '<a href="godkend.php?id='.$row_rsGodkend['id'].'">'.$row_rsGodkend['dansknavn'].'</a>';}?><br /> <?php } while ($row_rsGodkend = mysql_fetch_assoc($rsGodkend)); ?>[/code]Im trying to check if "dansknavn" is the same in both Skabalon and Sideinhold , and if its not then i want to post that link , if there is a match i want it to tell me.Sorry for being such a newbie :( Link to comment https://forums.phpfreaks.com/topic/35987-check-if-match-in-2-tables/#findComment-170729 Share on other sites More sharing options...
ineedhelp Posted January 28, 2007 Author Share Posted January 28, 2007 Please anyone? Link to comment https://forums.phpfreaks.com/topic/35987-check-if-match-in-2-tables/#findComment-171151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.