Page 1 of 1

disable checkbox

Posted: Sun Jun 19, 2005 8:54 am
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

Posted: Sun Jun 19, 2005 9:14 am
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

Posted: Sun Jun 19, 2005 9:28 am
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

Posted: Sun Jun 19, 2005 2:18 pm
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 "....";
  }
}

Posted: Sun Jun 19, 2005 4:38 pm
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

Posted: Sun Jun 19, 2005 4:41 pm
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