disable checkbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

disable checkbox

Post by Think Pink »

hello,
i have to make an aplication with innodb tables and i have a problem.
i have 2 tables
table_1
id1
text1

table_2
id2
text2
code_id_1 (foreign key for table_1.id1) ON DELETE RESTRICT

i select the database and each row has a checkbox[]
the question is how could i disable checkboxes of the fileds that are used?

example
table_1
1 blabla
2 balal
3 jhsd


table_2
1 aaaaaaaa 1
2 ssssssss 3
3 dddddddd 1
! the table_1.id='2' is not used by other tables

so here is how should look table_1
----------------------------------------------
checbox | id1 | text1 |
----------------------------------------------
checbox disabled | 1 | blabla |
checbox | 2 | balbal |
checbox disabled | 3 | jhsd |
----------------------------------------------

I hope i made my self clear.
thx in advance for your help
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

SELECT *,
       IF(table_2.code_id_1, 'enabled', 'disabled') AS status
FROM table_1
LEFT OUTER JOIN table2 ON table_2.code_id_1=table1_1.id_1
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post by Think Pink »

thx for your quick reply, but i have no ideea how to implement what you just wrote.
could you be a little more specific?
thx
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

$query = "........."; // what i posted above
$rs = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($rs))
{
  if ($row['status'] == 'enabled')
  {
    echo "<input type='...' name='...' value='...'/>;
  }
  else
  {
    echo "....";
  }
}
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post by Think Pink »

Code: Select all

SELECT *, IF(table_2.code_id_1 is null,'','disabled') AS status FROM table_1LEFT OUTER JOIN table2 ON table_2.code_id_1=table1_1.id_1
this is the query that worked for me. But now i have another problem. if in table_2 i have 20000 records, than i will have 20000 results when i try to list table 1
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post by Think Pink »

me again
i got it

here is the corect querry

Code: Select all

SELECT DISTINCT table_1.*, IF(table_2.code_id_1 is null,'','disabled') AS status FROM table_1 LEFT OUTER JOIN table_2 ON table_2.code_id_1=table_1.id_1
thx for your help
Post Reply