trassalg Posted August 2, 2007 Share Posted August 2, 2007 I have a list of checkboxes set up as a form that stores the data to a database cell in a comma separated string: For example: "12,13,18,110,118,21,28,31" Each checkbox has a name of "categories" with different values. What I'd like to do is the following: 1) Extract the data from the database 2) Separate each number it into an individual array value 3) Make the checkboxes in categories.php reflect the selected or non-selected state, based upon the results from the database (selected being the numbers in the database) Step 1 - I know how to do. Step 2 - I assume I need to use the explode function, no? Step 3 - Not a clue.... Below is the categories.php file, which I'm assuming is the program I need to add to. <?php include("includes/misc.inc"); include("includes/connection.inc"); ?> <table> <tr> <td> <strong>1. ALIMENTOS</strong><br> <input type="checkbox" name="categories" value="11">1.1 - AGRO<br> <input type="checkbox" name="categories" value="12">1.2 - INDUSTRIA<br><br> <strong>2. AMBIENTE</strong><br> <input type="checkbox" name="categories" value="21">2.1 - Ecología<br> <input type="checkbox" name="categories" value="22">2.2 - Energía<br> <input type="checkbox" name="categories" value="23">2.3 - Urbanismo<br><br> <strong>3. CIENCIA: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="31">3.1 - Biológicas<br> <input type="checkbox" name="categories" value="32">3.2 - Ciencias Todas<br> <input type="checkbox" name="categories" value="33">3.3 - De la Salud<br> <input type="checkbox" name="categories" value="34">3.4 - Duras<br> <input type="checkbox" name="categories" value="35">3.5 - Sociales<br><br> <strong>4. COMUNICACIÓN: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="41">4.1 - Medios<br> <input type="checkbox" name="categories" value="42">4.2 - Transporte<br><br> <strong>5. CULTURA: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="51">5.1 - Antropología Cultural<br> <input type="checkbox" name="categories" value="52">5.2 - Arte y Espectáculo<br> <input type="checkbox" name="categories" value="53">5.3 - Educación<br><br> <strong>6. ECONOMÍA: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="61">6.1 - MACRO<br> <input type="checkbox" name="categories" value="611">6.1.1 - ma Crédito y Finanzas<br> <input type="checkbox" name="categories" value="612">6.1.2 - ma Expo Impo<br> <input type="checkbox" name="categories" value="613">6.1.3 - ma Impuestos<br> <input type="checkbox" name="categories" value="614">6.1.4 - ma Inversiones<br> <input type="checkbox" name="categories" value="615">6.1.5 - ma Marketing<br> <input type="checkbox" name="categories" value="616">6.1.6 - ma Panorama<br> <input type="checkbox" name="categories" value="617">6.1.7 - ma Tendencias<br> <input type="checkbox" name="categories" value="618">6.1.8 - ma Teorías<br> <input type="checkbox" name="categories" value="62">6.2 - ma x Zona<br> <input type="checkbox" name="categories" value="621">6.2.1 - mi Empresas<br> <input type="checkbox" name="categories" value="622">6.2.2 - mi Capacitación<br> <input type="checkbox" name="categories" value="623">6.2.3 - mi Marketing<br> <input type="checkbox" name="categories" value="624">6.2.4 - mi Panorama<br> <input type="checkbox" name="categories" value="625">6.2.5 - mi Tendencias<br><br> <strong>7. JURÍDICA: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="71">7.1 - Comercial<br> <input type="checkbox" name="categories" value="72">7.2 - Constitucional y Varios<br> <input type="checkbox" name="categories" value="73">7.3 - Familia<br> <input type="checkbox" name="categories" value="74">7.4 - Laboral<br> <input type="checkbox" name="categories" value="75">7.5 - Penal<br><br> <strong>8. POLÍTICA: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="81">8.1 - Elecciones 2007<br> <input type="checkbox" name="categories" value="82">8.2 - Estado y Planificación<br> <input type="checkbox" name="categories" value="83">8.3 - Gobierno Nacional<br> <input type="checkbox" name="categories" value="84">8.4 - Internacionales<br> <input type="checkbox" name="categories" value="85">8.5 - Noticias<br> <input type="checkbox" name="categories" value="86">8.6 - Partidos<br> <input type="checkbox" name="categories" value="87">8.7 - Politica Regional<br><br> <strong>9. SALUD: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="91">9.1 - Calidad de Vida SA<br> <input type="checkbox" name="categories" value="92">9.2 - Conceptual<br> <input type="checkbox" name="categories" value="93">9.3 - Institucional<br> <input type="checkbox" name="categories" value="94">9.4 - Medicina<br> <input type="checkbox" name="categories" value="95">9.5 - Panorama<br><br> <strong>10. SOCIOLOGÍA: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="101">10.1 - Calidad de Vida SO<br> <input type="checkbox" name="categories" value="102">10.2 - Clases<br> <input type="checkbox" name="categories" value="103">10.3 - Control Social<br> <input type="checkbox" name="categories" value="104">10.4 - Demografía<br> <input type="checkbox" name="categories" value="105">10.5 - Economía Social<br> <input type="checkbox" name="categories" value="106">10.6 - Futuro CF<br> <input type="checkbox" name="categories" value="107">10.7 - Género<br> <input type="checkbox" name="categories" value="108">10.8 - Globalización<br> <input type="checkbox" name="categories" value="109">10.9 - Historia Toda<br> <input type="checkbox" name="categories" value="1010">10.10 - Juventud<br> <input type="checkbox" name="categories" value="1011">10.11 - Modas<br> <input type="checkbox" name="categories" value="1012">10.12 - Modernidad PosModernidad<br> <input type="checkbox" name="categories" value="1013">10.13 - ONG<br> <input type="checkbox" name="categories" value="1014">10.14 - Religión<br> <input type="checkbox" name="categories" value="1015">10.15 - Seguridad<br> <input type="checkbox" name="categories" value="1016">10.16 - Sociología<br> <input type="checkbox" name="categories" value="1017">10.17 - Trabajo<br><br> <strong>11. HERRAMIENTAS: SU DESARROLLO</strong><br> <input type="checkbox" name="categories" value="111">11.1 - ABC<br> <input type="checkbox" name="categories" value="112">11.2 - Anita<br> <input type="checkbox" name="categories" value="113">11.3 - Bibliografía<br> <input type="checkbox" name="categories" value="114">11.4 - Calendario 2007<br> <input type="checkbox" name="categories" value="115">11.5 - Clientes<br> <input type="checkbox" name="categories" value="116">11.6 - Gentes<br> <input type="checkbox" name="categories" value="117">11.7 - Medios<br> <input type="checkbox" name="categories" value="118">11.8 - Personal<br> <input type="checkbox" name="categories" value="119">11.9 - Tecnologís<br> <input type="checkbox" name="categories" value="1110">11.10 - Tema del...<br> <input type="checkbox" name="categories" value="1111">11.11 - Tendencias<br> <input type="checkbox" name="categories" value="1112">11.12 - Teorías<br> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/62991-sending-extracted-array-data-from-mysql-to-checkbox/ Share on other sites More sharing options...
ss32 Posted August 2, 2007 Share Posted August 2, 2007 yikes. well, your friend here is going to be the in_array(needle, haystack) function. if you could find a way to dynamically generate those fields, your task would be easy. otherwise what you are looking at is a lot of tedious work. anyway, you are going to need something along the lines of the following in each checkbox (assuming $userprefs is the array from the database) <input type="checkbox" <?php echo (in_array("12", $userprefs)) ? "checked=\"checked\"" : ""; ?> value="12" /> 1.2: blah blah... Link to comment https://forums.phpfreaks.com/topic/62991-sending-extracted-array-data-from-mysql-to-checkbox/#findComment-313755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.