geez, that's messy. the syntax is very outdated and might not even work on some servers (depending on php version and configuration). You should always use full
<?php ?> tags; and
<?= is bad practice as well. Plus, the php code is mixed with the html markup, making it very hard to track what's supposed to be happening.
I can appreciate your problems with your developer (hire a better one next time).
Let's start with what you actually want to do. This code is not in contex, so I can't guarantee that what I'm doing will work. Likewise, I don't know specifically what your developer's functions do, so I'll be using standard ones.
If you decide to try anything I suggest here, save the code you have now as a backup first.
PHP Code:
<?php
// i assume you're making a list of checkboxes,
// based on categories in your db. so:
// I don't know what the name of your table is
$table = 'tableNameGoesHere';
// fetch all category records
// this assumes you're already connected to your database
$result = mysql_query("SELECT * FROM $table");
// loop through each record and create each from input
while($r = mysql_fetch_assoc($result)){
// we're going to save each <input> in an array instead of printing them _right_now_
// this is more flexible, less error-prone, and easier to follow/ work with
if(in_array($r['category_id'],$excatg)){
// I don't know what $excatg is,
// but I'm assuming it's an array of options that should be checked by default
$inputs[] = '
<label><input type="checkbox" name="'.$r['category_id'].'" checked> '.$r['category_name'].'</label>';
}else{
$inputs[] = '
<label><input type="checkbox" name="'.$r['category_id'].'"> '.$r['category_name'].'</label>';
}
}
// print this where-ever it belongs in your html markup
// (I see it inside a <td> in your example)
// also, this will create a space-separated line of checkboxes,
// which may or may not be what you want and/or nice-looking.
// Alternatively, as an example,
// you could use '<br>' instead of ' ' to put each checkbox on its own line.
print implode(' ',$inputs);
?>
for anything more specific, please share more of your code.
p.s. please use the forum's bbcode tags (e.g., [ php ] /* php code goes here */ [/ php ] (no spaces)) to make your code more readable.
Bookmarks