Jump to content

Help with arrays (checkboxes)


BarneyJoe

Recommended Posts

With a fair amount of help I've just about managed to get a page working which displays a list of checkboxes and their titles using arrays.

The table they're based on in 'keywords', which contains Keyword_ID (PK), Keyword and Category.

The code looks like :

[code=php:0]<table width="942px" border="0" cellpadding="0" cellspacing="0" align="center">
<form name="form1" method="POST" action="photoKeywordsEdited.php">
<input type='hidden' name='Photo_ID' value='<?php echo $Photo_ID; ?>'>
<?php require_once('Connections/Photolibrary.php');
error_reporting(E_ALL & E_STRICT);
$Photo_ID = 1;
if (isset($_GET['Photo_ID'])) {
  $Photo_ID = intval($_GET['Photo_ID']);
}
mysql_select_db($database_Photolibrary, $Photolibrary);
$query_Keyword_Match = sprintf("SELECT * FROM photokeywords WHERE Photo_ID = %s", $Photo_ID);
$Keyword_Match = mysql_query($query_Keyword_Match, $Photolibrary) or die(mysql_error());
$photokeywords = array();
while ($row_Keyword_Match = mysql_fetch_assoc($Keyword_Match)) {
    $photokeywords[] = $row_Keyword_Match['Keyword_ID'];
}
$totalRows_Keyword_Match = mysql_num_rows($Keyword_Match);
$sql = "SELECT * FROM Keywords ORDER BY Category, Keyword";
$keywordArray = array();
$query = mysql_query($sql);



while ($result=mysql_fetch_assoc($query)) {
    $keywordArray[$result['Category']][] = $result;
}
$current_category = '';

foreach ($keywordArray as $categoryData)
{

if($current_category <> $categoryData[2]['Category'])
            {
                //open a new <tr>
                echo "<tr class=\"categorycell\">\n";
                //print the category as a header
                echo "<td colspan=\"10\">". $categoryData[2]['Category']."</td>\n";
                //close the <tr>
                echo "</tr>\n";
                $current_category = $categoryData[2]['Category'];

            }       

$row_count = 0;
//even row
if($row_count%2==0)
{
    $row_type = 'even';
}
//odd row
else
{
    $row_type = 'odd';             
}

echo("<tr class=\"".$row_type."\">");
    foreach ($categoryData as $keywordData) {
         

 
        echo("<td><input ");
if (in_array($keywordData['Keyword_ID'],$photokeywords)) {
            echo "checked ";
        }
        echo('name="ckbox['.$keywordData['Keyword_ID'].']" type="checkbox" class="tickbox2" id="ckbox['.$keywordData['Keyword_ID'].']"></td>');



        echo("<td>".$keywordData['Keyword'].'</td>');



        if ($counter==4) {
            echo('</tr><tr>');
            $counter = 0;
        } else {
            $counter++;
        }
    }

    echo('</tr>');
$row_count++;
}



?>

</table>[/code]

It should display each category distinctly, with the keywords of each category below.

It pretty much does so, but sometimes starts a new row after as few as three checkboxes with title. (There should be room for five.)

Below is some code that is produced :

[code]
<table width="942px" border="0" cellpadding="0" cellspacing="0" align="center">

<form name="form1" method="POST" action="photoKeywordsEdited.php">

<input type='hidden' name='Photo_ID' value='149'>

<tr class="categorycell">
<td colspan="10">Activities / sports and crafts</td>
</tr>

<tr class="even">
<td><input name="ckbox[31]" type="checkbox" class="tickbox2" id="ckbox[31]"></td>
<td>Ball games</td>
<td><input name="ckbox[32]" type="checkbox" class="tickbox2" id="ckbox[32]"></td>
<td>Climbing / mountaineering</td>
<td><input name="ckbox[33]" type="checkbox" class="tickbox2" id="ckbox[33]"></td>
<td>Crafts</td>
<td><input name="ckbox[34]" type="checkbox" class="tickbox2" id="ckbox[34]"></td>
<td>Cycling</td>
<td><input name="ckbox[35]" type="checkbox" class="tickbox2" id="ckbox[35]"></td>
<td>Dancing</td>
</tr>

<tr>
<td><input name="ckbox[36]" type="checkbox" class="tickbox2" id="ckbox[36]"></td>
<td>Fishing</td>
<td><input name="ckbox[37]" type="checkbox" class="tickbox2" id="ckbox[37]">
</td><td>Golf</td>
<td><input name="ckbox[38]" type="checkbox" class="tickbox2" id="ckbox[38]"></td>
<td>Horse riding / pony trekking</td>
<td><input name="ckbox[39]" type="checkbox" class="tickbox2" id="ckbox[39]"></td>
<td>Music</td>
<td><input name="ckbox[40]" type="checkbox" class="tickbox2" id="ckbox[40]"></td>
<td>Paragliding / hang gliding</td>
</tr>

<tr>
<td><input name="ckbox[41]" type="checkbox" class="tickbox2" id="ckbox[41]"></td>
<td>Sailing</td>
<td><input name="ckbox[42]" type="checkbox" class="tickbox2" id="ckbox[42]"></td>
<td>Shopping / shopping centre</td>
<td><input name="ckbox[43]" type="checkbox" class="tickbox2" id="ckbox[43]"></td>
<td>Skiing</td>
<td><input name="ckbox[44]" type="checkbox" class="tickbox2" id="ckbox[44]"></td>
<td>Swimming</td>
<td><input name="ckbox[45]" type="checkbox" class="tickbox2" id="ckbox[45]"></td>
<td>Walking / pathways</td>
</tr>

<tr>
<td><input name="ckbox[46]" type="checkbox" class="tickbox2" id="ckbox[46]"></td>
<td>Water sports</td>
</tr>

<tr class="categorycell">
<td colspan="10">Events</td>
</tr>

<tr class="even">
<td><input name="ckbox[72]" type="checkbox" class="tickbox2" id="ckbox[72]"></td>
<td>Carnival</td>
<td><input name="ckbox[73]" type="checkbox" class="tickbox2" id="ckbox[73]"></td>
<td>Ceremony / pageantry</td>
<td><input name="ckbox[74]" type="checkbox" class="tickbox2" id="ckbox[74]"></td>
<td>Fair</td>
<td><input checked name="ckbox[76]" type="checkbox" class="tickbox2" id="ckbox[76]"></td>
<td>Festival</td>
</tr>

<tr>
<td><input checked name="ckbox[75]" type="checkbox" class="tickbox2" id="ckbox[75]"></td>
<td>Flag / heraldry</td>
<td><input name="ckbox[77]" type="checkbox" class="tickbox2" id="ckbox[77]"></td>
<td>Parade</td>
</tr>

<tr class="categorycell">
<td colspan="10">Flora and fauna</td>
</tr>

<tr class="even">
<td><input name="ckbox[85]" type="checkbox" class="tickbox2" id="ckbox[85]"></td>
<td>Amphibian</td>
<td><input name="ckbox[78]" type="checkbox" class="tickbox2" id="ckbox[78]"></td>
<td>Bird</td>
<td><input name="ckbox[79]" type="checkbox" class="tickbox2" id="ckbox[79]"></td>
<td>Fish</td>
</tr>

<tr>
<td><input name="ckbox[80]" type="checkbox" class="tickbox2" id="ckbox[80]"></td>
<td>Flower / plant</td>
<td><input name="ckbox[86]" type="checkbox" class="tickbox2" id="ckbox[86]">
</td><td>Fungus</td>
<td><input name="ckbox[81]" type="checkbox" class="tickbox2" id="ckbox[81]"></td>
<td>Insect</td>
<td><input name="ckbox[82]" type="checkbox" class="tickbox2" id="ckbox[82]"></td>
<td>Mammal</td>
<td><input name="ckbox[83]" type="checkbox" class="tickbox2" id="ckbox[83]"></td>
<td>Reptile</td>
</tr>

<tr>
<td><input name="ckbox[84]" type="checkbox" class="tickbox2" id="ckbox[84]"></td>
<td>Tree / shrub</td>
</tr>

<tr class="categorycell">
<td colspan="10">Physical features / landscapes</td>
</tr>

<tr class="even">
<td><input name="ckbox[47]" type="checkbox" class="tickbox2" id="ckbox[47]"></td>
<td>Aerial view</td>
<td><input name="ckbox[48]" type="checkbox" class="tickbox2" id="ckbox[48]"></td>
<td>Beach / bay / cove</td>
<td><input name="ckbox[49]" type="checkbox" class="tickbox2" id="ckbox[49]"></td>
<td>Causeway</td>
<td><input name="ckbox[50]" type="checkbox" class="tickbox2" id="ckbox[50]"></td>
<td>Cave</td>
</tr>

<tr>
<td><input name="ckbox[51]" type="checkbox" class="tickbox2" id="ckbox[51]"></td>
<td>Cityscape</td>
<td><input name="ckbox[52]" type="checkbox" class="tickbox2" id="ckbox[52]"></td>
<td>Cliff</td>
<td><input name="ckbox[53]" type="checkbox" class="tickbox2" id="ckbox[53]"></td>
<td>Coast</td>
<td><input name="ckbox[54]" type="checkbox" class="tickbox2" id="ckbox[54]"></td>
<td>Crag / rock / tor</td>
<td><input name="ckbox[55]" type="checkbox" class="tickbox2" id="ckbox[55]"></td>
<td>Dune</td>
</tr>

<tr>
<td><input name="ckbox[56]" type="checkbox" class="tickbox2" id="ckbox[56]"></td>
<td>Estuary / marsh</td>
<td><input name="ckbox[57]" type="checkbox" class="tickbox2" id="ckbox[57]"></td>
<td>Farmland</td>
<td><input name="ckbox[58]" type="checkbox" class="tickbox2" id="ckbox[58]"></td>
<td>Forest / trees</td>
<td><input name="ckbox[59]" type="checkbox" class="tickbox2" id="ckbox[59]"></td>
<td>Hill</td>
<td><input name="ckbox[60]" type="checkbox" class="tickbox2" id="ckbox[60]"></td>
<td>Island</td>
</tr>

<tr>
<td><input name="ckbox[61]" type="checkbox" class="tickbox2" id="ckbox[61]"></td>
<td>Lake / loch / tarn / reservoir</td>
<td><input name="ckbox[62]" type="checkbox" class="tickbox2" id="ckbox[62]"></td>
<td>Landscapes (general)</td>
<td><input name="ckbox[63]" type="checkbox" class="tickbox2" id="ckbox[63]"></td>
<td>Lava</td>
<td><input name="ckbox[64]" type="checkbox" class="tickbox2" id="ckbox[64]"></td>
<td>Limestone pavement</td>
<td><input name="ckbox[65]" type="checkbox" class="tickbox2" id="ckbox[65]"></td>
<td>Moor / heathland</td>
</tr>

<tr>
<td><input name="ckbox[66]" type="checkbox" class="tickbox2" id="ckbox[66]"></td>
<td>Mountain</td>
<td><input name="ckbox[67]" type="checkbox" class="tickbox2" id="ckbox[67]"></td>
<td>Peninsula / headland</td>
<td><input name="ckbox[68]" type="checkbox" class="tickbox2" id="ckbox[68]"></td>
<td>River</td>
<td><input name="ckbox[69]" type="checkbox" class="tickbox2" id="ckbox[69]"></td>
<td>Sea / waves</td>
<td><input name="ckbox[70]" type="checkbox" class="tickbox2" id="ckbox[70]"></td>
<td>Valley / gorge / glen</td>
</tr>

<tr>
<td><input name="ckbox[71]" type="checkbox" class="tickbox2" id="ckbox[71]"></td>
<td>Waterfall</td>
</tr>

<tr class="categorycell">
<td colspan="10">Places of Interest / buildings</td>
</tr>

<tr class="even">
<td><input name="ckbox[2]" type="checkbox" class="tickbox2" id="ckbox[2]"></td>
<td>Ancient monument</td>
<td><input name="ckbox[3]" type="checkbox" class="tickbox2" id="ckbox[3]"></td>
<td>Aquarium</td>
<td><input name="ckbox[4]" type="checkbox" class="tickbox2" id="ckbox[4]"></td>
<td>Aqueduct / viaduct</td>
<td><input name="ckbox[5]" type="checkbox" class="tickbox2" id="ckbox[5]"></td>
<td>Bridge</td>
</tr><tr><td><input name="ckbox[6]" type="checkbox" class="tickbox2" id="ckbox[6]"></td>
<td>Castle / fort</td>
<td><input name="ckbox[7]" type="checkbox" class="tickbox2" id="ckbox[7]"></td>
<td>Country park</td>
<td><input name="ckbox[8]" type="checkbox" class="tickbox2" id="ckbox[8]"></td>
<td>Distillery</td>
<td><input name="ckbox[9]" type="checkbox" class="tickbox2" id="ckbox[9]"></td>
<td>Ecclesiastical building</td>
<td><input name="ckbox[10]" type="checkbox" class="tickbox2" id="ckbox[10]"></td>
<td>Exhibition centre / conference centre</td>
</tr>

<tr>
<td><input name="ckbox[11]" type="checkbox" class="tickbox2" id="ckbox[11]"></td>
<td>Garden / park / parkland</td>
<td><input name="ckbox[12]" type="checkbox" class="tickbox2" id="ckbox[12]"></td>
<td>Golf course</td>
<td><input name="ckbox[13]" type="checkbox" class="tickbox2" id="ckbox[13]"></td>
<td>Historic house</td>
<td><input name="ckbox[14]" type="checkbox" class="tickbox2" id="ckbox[14]"></td>
<td>Industrial building</td>
<td><input name="ckbox[15]" type="checkbox" class="tickbox2" id="ckbox[15]"></td>
<td>Lighthouse</td>
</tr>

<tr>
<td><input name="ckbox[16]" type="checkbox" class="tickbox2" id="ckbox[16]"></td>
<td>Model village</td>
<td><input name="ckbox[17]" type="checkbox" class="tickbox2" id="ckbox[17]"></td>
<td>Monument / memorial / grave / statue / fountain</td>
<td><input name="ckbox[18]" type="checkbox" class="tickbox2" id="ckbox[18]"></td>
<td>Museum / art gallery / heritage centre</td>
<td><input name="ckbox[19]" type="checkbox" class="tickbox2" id="ckbox[19]">
</td><td>National park / forest park / regional park</td>
<td><input name="ckbox[20]" type="checkbox" class="tickbox2" id="ckbox[20]"></td>
<td>Notable building (other)</td>
</tr>

<tr>
<td><input name="ckbox[21]" type="checkbox" class="tickbox2" id="ckbox[21]"></td>
<td>Notable structure (other)</td>
<td><input name="ckbox[22]" type="checkbox" class="tickbox2" id="ckbox[22]"></td>
<td>Power station / wind farm</td>
<td><input name="ckbox[23]" type="checkbox" class="tickbox2" id="ckbox[23]">
</td><td>Street scene</td>
<td><input name="ckbox[24]" type="checkbox" class="tickbox2" id="ckbox[24]"></td>
<td>Theatre / cinema / concert hall / opera house / art centre</td>
<td><input name="ckbox[25]" type="checkbox" class="tickbox2" id="ckbox[25]"></td>
<td>Theme park</td>
</tr>

<tr>
<td><input name="ckbox[26]" type="checkbox" class="tickbox2" id="ckbox[26]">
</td><td>University / college</td>
<td><input name="ckbox[27]" type="checkbox" class="tickbox2" id="ckbox[27]"></td>
<td>Vineyard</td>
<td><input name="ckbox[28]" type="checkbox" class="tickbox2" id="ckbox[28]"></td>
<td>Visitor centre</td>
<td><input name="ckbox[29]" type="checkbox" class="tickbox2" id="ckbox[29]"></td>
<td>Water park</td>
<td><input name="ckbox[30]" type="checkbox" class="tickbox2" id="ckbox[30]"></td>
<td>Wildlife park / zoo / safari park / farm park</td>
</tr>

<tr></tr><tr class="categorycell">
<td colspan="10">Transport and travel</td>
</tr>

<tr class="even">
<td><input name="ckbox[87]" type="checkbox" class="tickbox2" id="ckbox[87]"></td>
<td>Bus</td>
<td><input name="ckbox[88]" type="checkbox" class="tickbox2" id="ckbox[88]"></td>
<td>Canal</td>
<td><input name="ckbox[89]" type="checkbox" class="tickbox2" id="ckbox[89]"></td>
<td>Car / taxi</td>
<td><input name="ckbox[91]" type="checkbox" class="tickbox2" id="ckbox[91]"></td>
<td>Road / road sign</td><td><input name="ckbox[90]" type="checkbox" class="tickbox2" id="ckbox[90]"></td>
<td>Ship / boat / ferry / harbour</td>
</tr>

<tr>
<td><input name="ckbox[92]" type="checkbox" class="tickbox2" id="ckbox[92]"></td>
<td>Train / railway</td>
</tr>

<tr class="categorycell">
<td colspan="10">Weather and seasons</td>
</tr>

<tr class="even">
<td><input name="ckbox[93]" type="checkbox" class="tickbox2" id="ckbox[93]"></td>
<td>Autumn</td>
<td><input name="ckbox[94]" type="checkbox" class="tickbox2" id="ckbox[94]"></td>
<td>Bore</td>
<td><input name="ckbox[104]" type="checkbox" class="tickbox2" id="ckbox[104]"></td>
<td>Mist</td>
<td><input name="ckbox[95]" type="checkbox" class="tickbox2" id="ckbox[95]"></td>
<td>Night</td>
</tr>

<tr>
<td><input name="ckbox[96]" type="checkbox" class="tickbox2" id="ckbox[96]"></td>
<td>Rain</td>
<td><input name="ckbox[105]" type="checkbox" class="tickbox2" id="ckbox[105]"></td>
<td>Rainbow</td>
<td><input name="ckbox[97]" type="checkbox" class="tickbox2" id="ckbox[97]"></td>
<td>Sky / cloud</td>
<td><input name="ckbox[98]" type="checkbox" class="tickbox2" id="ckbox[98]"></td>
<td>Snow / ice</td>
<td><input name="ckbox[99]" type="checkbox" class="tickbox2" id="ckbox[99]"></td>
<td>Spring</td>
</tr>

<tr>
<td><input checked name="ckbox[100]" type="checkbox" class="tickbox2" id="ckbox[100]"></td>
<td>Summer</td>
<td><input name="ckbox[101]" type="checkbox" class="tickbox2" id="ckbox[101]"></td>
<td>Sunrise / sunset</td>
<td><input name="ckbox[102]" type="checkbox" class="tickbox2" id="ckbox[102]"></td>
<td>Winter</td>
</tr>

</table>[/code]

So from that, within each 'Category' the checkboxes and ketwords should appear 5 to a row. It mostly works, but for some reason a new row is created prematurely after the following keywords :

Festival (first row of 'Events')
Fish (first row of 'Flora and Fauna')
Cave (first row of 'Physical features')
Bridge (first row of 'Places of Interest')
Night (first row of 'Weather and Seasons')

Any ideas what's causing that, and how to fix it greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/32065-help-with-arrays-checkboxes/
Share on other sites

I'm not sure where your problem is, but I think your code is overcomplicated. For instance you don't need to put the second result set into an array and then loop through that array, you can just loop through the record set. How 'bout you try this:
(not tested so there may be some minor errors)
[code]<table width="942px" border="0" cellpadding="0" cellspacing="0" align="center">
<form name="form1" method="POST" action="photoKeywordsEdited.php">
<input type='hidden' name='Photo_ID' value='<?php echo $Photo_ID; ?>'>

<?php
require_once('Connections/Photolibrary.php');
error_reporting(E_ALL & E_STRICT);
$Photo_ID = 1;

if (isset($_GET['Photo_ID'])) {
    $Photo_ID = intval($_GET['Photo_ID']);
}

//Get photokeywords & put into array
mysql_select_db($database_Photolibrary, $Photolibrary);
$query_Keyword_Match = sprintf("SELECT * FROM photokeywords WHERE Photo_ID = %s", $Photo_ID);
$Keyword_Match = mysql_query($query_Keyword_Match, $Photolibrary) or die(mysql_error());
$photokeywords = array();
while ($row_Keyword_Match = mysql_fetch_assoc($Keyword_Match)) {
    $photokeywords[] = $row_Keyword_Match['Keyword_ID'];
}

//Get all the keywords
$sql = "SELECT * FROM Keywords ORDER BY Category, Keyword";
$query = mysql_query($sql);

$current_category = "";
$row_type = "";
$column = 1;

while ($keyword=mysql_fetch_assoc($query)) {

    //If new category close previous row & display new category
    if ($keyword['Category']!=$current_category) {
        if ($current_category && $column !=1 ) { echo "</tr>\n"; }
        $current_category = $keyword['Category'];
        echo "<tr class=\"categorycell\"><td colspan=\"10\">$current_category}</td></tr>\n";
        $column = 1;
    }

    //Create new row if 1st keyword
    if ($column == 1) {
        echo "<tr class=\"".(($row_type=="odd")?"even":"odd")."\">";
    }

    //Display the checkbox
    echo "<td>"
    echo "<input type=\"checkbox\" class=\"tickbox2\"";
    if (in_array($keyword['Keyword_ID'],$photokeywords)) { echo " checked"; }
    echo " name=\"ckbox[".$keyword['Keyword_ID']."]\" id=\"ckbox[".$keyword['Keyword_ID']."]\">";
    echo "</td>\n";

    //Display the Keyword
    echo "<td>".$keyword['Keyword']."</td>\n";

    //Close the row if 5th keyword OR increase column count
    if ($column == 5) { echo "</tr>"; $column = 1; }
    else { $column++; }
}

if ($column != 1) { echo "</tr>"; }
?>

</table>
[/code]
Thank you! It pretty much worked straight off, but with a stray ; and a rogue } :

[code=php:0]//Display the checkbox
    echo "<td>"[b];[/b][/code]

and

[code=php:0]echo "<tr class=\"categorycell\"><td colspan=\"10\">$current_category[b]}[/b]</td></tr>\n";[/code]

The alternating row colours aren't working tho' - whilst it would be nice, the functionality is more important than the aesthetics.

From this code sample, it looks as tho it's doing every row as odd :

[code]
<tr class="categorycell"><td colspan="10">Activities / sports and crafts</td></tr>
<tr class="odd"><td><input type="checkbox" class="tickbox2" name="ckbox[31]" id="ckbox[31]"></td>
<td>Ball games</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[32]" id="ckbox[32]"></td>
<td>Climbing / mountaineering</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[33]" id="ckbox[33]"></td>
<td>Crafts</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[34]" id="ckbox[34]"></td>
<td>Cycling</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[35]" id="ckbox[35]"></td>
<td>Dancing</td>
</tr><tr class="odd"><td><input type="checkbox" class="tickbox2" name="ckbox[36]" id="ckbox[36]"></td>
<td>Fishing</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[37]" id="ckbox[37]"></td>
<td>Golf</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[38]" id="ckbox[38]"></td>
<td>Horse riding / pony trekking</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[39]" id="ckbox[39]"></td>
<td>Music</td>
<td><input type="checkbox" class="tickbox2" name="ckbox[40]" id="ckbox[40]"></td>
<td>Paragliding / hang gliding</td>
</tr><tr class="odd"><td><input type="checkbox" class="tickbox2" name="ckbox[41]" id="ckbox[41]"></td>
<td>Sailing</td>[/code]
change this:
[code]<?php
    //Create new row if 1st keyword
    if ($column == 1) {
        echo "<tr class=\"".(($row_type=="odd")?"even":"odd")."\">";
    }
?>[code]

To this:
[code]<?php
    //Create new row if 1st keyword
    if ($column == 1) {
        $row_type = ($row_type=="odd")?"even":"odd";
        echo "<tr class=\"".$row_type."\">";
    }
?>[/code][/code][/code]
Thank you - that works great.

I guess the last little trick is to tidy up the checkboxes. I have two tickbox styles :

[code]
.tickbox {
border: 0;
background-color: #FFFFFF;
}
.tickbox2 {
border: 0;
background-color: #EDDB89;
}
[/code]

Is it possible to modify the code :

[code=php:0]//Create new row if 1st keyword
    if ($column == 1) {
        $row_type = ($row_type=="odd")?"even":"odd";
        echo "<tr class=\"".$row_type."\">";
    }


    //Display the checkbox
    echo "<td width=\"2%\">";
    echo "<input type=\"checkbox\" class=\"tickbox2\"";
    if (in_array($keyword['Keyword_ID'],$photokeywords)) { echo " checked"; }
    echo " name=\"keyword[]\" value=\"".$keyword['Keyword_ID']."\">";
    echo "</td>\n";[/code]

so that .tickbox is applies in odd rows, and .tickbox2 is applied in even rows?
An easier and more elegant solution would be to change the classes to "tickbox_odd" and "tickbox_even"

Then change this:
[code]echo "<input type=\"checkbox\" class=\"tickbox2\"";[/code]

To this:
[code]echo "<input type=\"checkbox\" class=\"tickbox_".$row_type."\"";[/code]
Thank you! It actually is all looking exactly as I had it when I originally hard coded all the checkboxes, so looking good.

The last little detail would be to have the first row in each category be 'odd' - so I've been trying to add in :

[code=php:0]$counter = 0;[/code]

In a few likely looking places, but without any joy - where exactly would it need to go?
[code]<?php
    //If new category close previous row & display new category
    if ($keyword['Category']!=$current_category) {
        if ($current_category && $column !=1 ) { echo "</tr>\n"; }
        $current_category = $keyword['Category'];
        echo "<tr class=\"categorycell\"><td colspan=\"10\">$current_category}</td></tr>\n";
        $column = 1; $row_type="";
    }

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.