Forum Moderators: coopster

Message Too Old, No Replies

checking to see if 2 values are in 2 db

checking to see if a value is in 2 diff tables

         

weddingm

5:02 am on Sep 30, 2009 (gmt 0)

10+ Year Member



I have x value in db 1 and y values in db 2. I need to find out if there are any x values in db 1 that do not exist as y values in db 2.

Basically I need to know that all users exist in both dbs and output all that do not exist in both.

Karma

10:50 am on Sep 30, 2009 (gmt 0)

10+ Year Member



<?php

// Setup connection parms for database
$db_server = "";
$db_databaseName = "";
$db_username = "";
$db_password = "";
mysql_connect($db_server,$db_username,$db_password) or die("Unable to connect to database");
mysql_select_db("$db_databaseName") or die("Unable to select database $db_databaseName");

// Select all records from 'tbl_everybody' that are not in the 'tbl_justgirls' table
$sql = "SELECT fld_name FROM tbl_everybody WHERE tbl_everybody.fld_name NOT IN (select fld_name from tbl_justgirls)";

$result = mysql_query($sql) or die (mysql_error());
$number = mysql_num_rows($result);

while($row = mysql_fetch_array($result))
{
echo $row['fld_name'];
echo "<br />";
}

?>

weddingm

5:19 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



Thanks Karma, I will give it a try.