mythri Posted December 14, 2014 Share Posted December 14, 2014 Hello, I want to show checkbox is checked when there is entry of that id in a table in my database. I have 2 tables page and access_level. I am getting data from page table and displays it in <ul><li> tag with checkbox to select all or only few. After selecting the checkbox, i will store only selected checkbox value in access_level table along with table id. Page link and page name details will be stored in page table. Now if i want to edit , i should display all the pages which is there in page table and i should also mark checked to those which are already stored in access_level table. I am using LEFT OUT JOIN, It displays all the pages. But it is not displaying the check mark to those which are already selected. Here is my code <?php $s1 = mysql_query("SELECT pages.page_id, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.department, access_level.position, access_level.active FROM pages LEFT OUTER JOIN access_level ON pages.page_id=access_level.page_id WHERE access_level.department=".$department." AND access_level.position=".$position." AND pages.code='sn'") or die(mysql_error()); while($s2 = mysql_fetch_array($s1)) { ?> <tr><td><li><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['page_id']; ?>" <?php if($row['pgid'] === $s2['page_id']) echo 'checked="checked"';?> /> here is my pages table access_level In access_level table i do not have page ids 8 and 9. But i want to display that also from pages table and for 1 to 7 and 10 i should display check mark. How i can achieve this? Please Help Link to comment https://forums.phpfreaks.com/topic/293093-show-checkbox-is-checked-based-on-database-value-by-joining-two-tables/ Share on other sites More sharing options...
mythri Posted December 15, 2014 Author Share Posted December 15, 2014 This problem is resolved Link to comment https://forums.phpfreaks.com/topic/293093-show-checkbox-is-checked-based-on-database-value-by-joining-two-tables/#findComment-1499598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.