View Single Post
Old 11-12-2012, 05:45 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Sure. I don't know what your task primary key is, so I'll just make one up that I'll call taskid. If its composite, this can still be done, but you'll need to pass both to the value (typically done easiest with serialization).
PHP Code:
print '<form method="post" action="">';
$toqmysql_query("SELECT * FROM tasks WHERE done=0");
while (
$row mysql_fetch_assoc($toq))
{
    
printf('<label for="%d"><span class="labelsystem">%s</span><span class="labelregion">%s</span><span class="labeldescription">%s</span></label>' PHP_EOL$row['taskid'], $row['system'], $row['region'], $row['description']);
    
printf('<input id="%d" type="checkbox" name="todo[]" value="%d" />' PHP_EOL$row['taskid'], $row['taskid']);
}
print 
'</form>'
Which should give you similar to what you have in the first screenshot. You can use CSS for the markup of that instead; I removed the - from them as I don't like them. You should be able to use the CSS pseudo classes :before and :after to add them if you want (won't work with IE < 6.0 of course).

Then when you process them, you simply retrieve from the todo array:
PHP Code:
if (isset($_POST['todo']) && is_array($_POST['todo']))
{
    
// This is where we write validation and verification.  I just assume a flat integer
    
function isIntString($in)
    {
        
$bResult false;
        
$int = (int)$in;
        if ((string)
$int == $in)
        {
            
$bResult true;
        }
        return 
$bResult;
    }

    
$aTodo array_filter($_POST['todo'], 'isIntString');
    
    if (!empty(
$aTodo))
    {
        
// here we would handle SQL if it needs to be escaped (integers do not).
        
$sQry 'UPDATE tasks SET done = 1 WHERE taskid IN (' implode(', '$aTodo) . ')';
        
// and go from here to update
    
}

Like that.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
lewishowe (11-14-2012)