Jump to content

2 tables w/same fields compare?


dbrimlow

Recommended Posts

I have two tables that are exactly the same in stucture.
table 1 gets populated by an auto dump sent via a custom 3rd party inhouse application. It works fine for 90% of our tables, but for one table the application is limited ... so I created a manual table to allow showing the same array as all the others.

table 2 is manually populated, to provide data in fields not usually included in table 1 dump.

I then have 2 sets of arrays that search both tables for the same content, and defines how it should display on the page in a description and in a bulleted amenities list. eg:


Table1 select includes -
if ($myrow[coop] == "COOPERATIVE") {
$description .= ", COOP";
$building[]="Cooperative";
}

if ($myrow[coop] == "CONDOMINIUM") {
$description .= ", CONDO";
$building[]="Condominium";
}
if ($myrow[coop] == "CONDOP") {
$description .= ", CONDOP";
$building[]="Cond-Op";
} etc., etc.

Table2 select includes:

if ($mytownhouse[bldg_type] == "townhouse") {
$description .= ", TOWNHOUSE";
$building[]="Townhouse";
}

if($mytownhouse[bldg_type] == "brownstone") {
$description .= ", BROWNSTONE";
$building[]="Brownstone";
} etc., etc.

This worked fine for the first year or so, it would provide data missing in table 1 with data from table 2.

But now, after a recent upgrade of our custom app., the dump is including some of the data that was missing from table1. So now, I am getting duplicate amenities.

These conditional arrays are both HUGE lines of text - easily spanning over 800 lines of code.

What I want know, is if there is an EASY way for me to exclude any duplicates among the tables from displaying, and set one table as the default source in the event of a duplicate?

I can compare each and every field and if both have data, ignore one or the other, but there MUST be a simple tables wide compare statement. Something like:

if (($myrow[$building()] !="") && ($mytownhouse[$building()] !="") {

$building()=$mytownhouse [$building()];
}

I don't know if I explained this coherently or not, and I don't think the above would work.

Dave
Link to comment
Share on other sites

Ideally this should be done in the MySQL query, but I don't know enough about your system to write it for you. It sounds like you are doing things the hard way - bigtime.

You could probably solve your problem quickly with the PHP function array_unique(), but again from your description I'm not clear on what you're after.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.