Jump to content

check if match in 2 tables


ineedhelp

Recommended Posts

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
-B

So 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

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, b
WHERE
  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
Hmm i cant seem to get it to work , gah i feel like such a newbie .. wich i am heh

This 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, sideindhold
WHERE
  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 :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.