Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Sobota, 28. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Simple example of checkbox please

phpMyEdit Features     Simple example of checkbox please
Odoslať novú tému   Odpovedať na tému    
 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2008-08-01 09:03
Návrat hore  Odpovedať s citátom     

I have a BOOLEAN field which I wish to edit using a checkbox.

How do I pass the existing value to the checkbox (if 1 it should be checked, if 0 it should be unchecked), and receive the returned value from the form?

Here's what I've been working on:

Kód:
$opts['fdd']['attendance'] = array(
  'name'     => 'Attendance',
  'select'   => 'C',
  'maxlen'   => 1,
  'sort'     => true,
  'options'  => 'AVCPVDLF',
  'values2'  => ""
);


I've found by brute force methods (repeated trial and inevitable error!) that 'values2' has to be used to get a checkbox to appear on the Change screen, but the documentation says little about 'values2'.

As a secondary question, can someone explain 'values2' for me?

Many thanks in advance for your help!

 
((Kakashi))     Založený: 17.09.2008   Príspevky: 3  
Príspevok Zaslal: 2008-09-18 05:58
Návrat hore  Odpovedať s citátom     

Looks like we have the same problem...did you find a fix?

 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2008-09-18 08:21
Návrat hore  Odpovedať s citátom     

No. I worked around the problem using radio-buttons, so that instead of "Attendance" as a boolean I had an enumeration ("Absent", "Present").

 
foxylady337     Založený: 24.07.2008   Príspevky: 10  
Príspevok Zaslal: 2008-09-18 17:25
Návrat hore  Odpovedať s citátom     

This segment of code works for me.

It may not necessarily be the best way of doing things(!), and I stole the idea from someone else on the Forum - can't remember who it was now, but no doubt you could search for it. Variable $space is defined elsewhere in the file thus:
Kód:

$space = "\t\t<td>&nbsp;</td>\n";

as a way of ensuring that a cell in a table is displayed even if the entry is blank.

Kód:

echo "<TABLE BORDER=\"5\" CELLPADDING=\"5\" CELLSPACING=\"0\" NOWRAP=\"NOWRAP\"
     BGCOLOR=\"#FFFFFF\" BORDERCOLORLIGHT=\"#009dbe\" BORDERCOLORDARK=\"#0d38981\">
      <TR>
        <TD ALIGN=\"CENTER\" COLSPAN=6><FONT COLOR=\"#FF0000\">MEMBERS' ATTENDANCE AT MEETING ON  $MEETING_DATE</FONT></TD>
      </TR>";
/*
* The following query is used to generate a two-column table, with the member's name in the first column,
* and radio-buttons for the three possible attendance values in the second. The values are translated from
* 0, 1 and 2 to Absent, Present and Credit respectively, as they are read from the database.
* The use of "group" before each attendance_key value, and its removal when the time comes to update
* tbl_attendance is probably unnecessary - it's code I borrowed from elsewhere, and it works, so best left alone!
* Later added value 3 for "Excluded"
*/

$query= "SELECT IFNULL(m.known_as, CONCAT(m.Initial, ' ', m.name))as 'whole_name',
    CASE a.attendance
    WHEN 0 THEN concat('<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"1\"        >Present',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"0\" checked>Absent',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"2\"        >Credit',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"3\"        >Excluded')
    WHEN 1 THEN concat('<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"1\" checked>Present',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"0\"        >Absent',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"2\"        >Credit',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"3\"        >Excluded')
    WHEN 2 THEN concat('<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"1\"        >Present',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"0\"        >Absent',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"2\" checked>Credit',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"3\"        >Excluded')
    WHEN 3 THEN concat('<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"1\"        >Present',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"0\"        >Absent',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"2\"        >Credit',
                       '<input type=\"radio\" name=\"group',attendance_key,'\" VALUE=\"3\" checked>Excluded')
    END
    FROM $TABLE_MEMBERS m
    LEFT JOIN $TABLE_ATTENDANCE a on Counter = member_key
    LEFT JOIN $TABLE_CALENDAR c on calendar_key = meeting_key
    WHERE ((m.year_left IS NULL) OR (m.year_left > $effective_year)) AND m.year_join <= $effective_year + 1 ".
    "AND honorary=\"No\" AND honorary_life=\"No\" ".
    "AND (start_date = \"$MEETING_DATE\" )
    ORDER BY m.name, m.Initial
    ";

foreach ($_POST as $k => $v) {
  $radio_query = "UPDATE ".$TABLE_ATTENDANCE." SET attendance=".$v." WHERE attendance_key=".substr($k,5);
  $radio_result = mysql_query($radio_query) or die('Insertion failed: ' . mysql_error());
}


// echo $query."<BR>"; // DEBUG
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo (($col_value =='') ? $space: "\t\t<td>$col_value</td>\n");
    }
}

echo "</TABLE>";
echo "<BR>";
echo "<INPUT TYPE=SUBMIT VALUE=\"Confirm Changes\">
      <INPUT TYPE=RESET VALUE=\"Cancel Changes\">
      </FORM>";


I hope this will help you solve your problem.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov