Jump to content

comparing results from two tables?


wmguk

Recommended Posts

Hey,

 

I have a db and several tables, now the main table is Clients. the second table is Variables.

 

In the variables table there are lists of business levels (level) and in the list of clients they use that sector list.

 

what I need to do is check the clients table to see what levels are in use, and then if they are in use dont allow a deletion...

 

my current script is:

 

$sql_level = "SELECT DISTINCT level FROM clients" ;
$result_level = mysql_query($sql_level);

while($row = mysql_fetch_array($result_level)) 
{ 
$level = $row['level'];

$sql_level2 = "SELECT * FROM variables WHERE title = $level" ;
$result_level2 = mysql_query($sql_level2);

while($row = mysql_fetch_array($result_level2)) 
{ 
$level_name = $row['title'];
}
}

 

however if I echo the results I get nothing...

 

I tried this:

 

$sql_level = "SELECT DISTINCT level FROM clients" ;
$result_level = mysql_query($sql_level);

while($row = mysql_fetch_array($result_level)) 
{ 
$level = $row['level'];
}

echo $level;

 

however still nothing.... but there are things in the DB!

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/148737-comparing-results-from-two-tables/
Share on other sites

Sorry, I'm trying to see what levels are in use.

 

CLIENTS :

client_id  | company | address | postcode | active | date | comments  | cltype | sector | level | nextactivity

1          | TEST      |  Test    |  Test      |    1    |010101|    test      |    1    | industrial  | active  |  010201

 

VARIABLES:

ref | title | sector | level |

_______________________

1  |  active  |  0  |  1  |

 

I just need to check if any of the variables are in use in the clients table, so that if they are my delete script cannot work...

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.