Skip to main content
Known Participant
July 7, 2012
Question

Organizing checkbox group in rows and columns

  • July 7, 2012
  • 2 replies
  • 1907 views

OK! I have a checkbox group populated in this way, I will chose from maybe 100 drills for golf players and put the drill_ID it together in a lookup table with players_id.

Maybe up to 20 drills per player.

Now can I organice the checkbox group in columns or rows so I dont get a 100 long list straight down?

This topic has been closed for replies.

2 replies

David_Powers
Inspiring
July 7, 2012

If you're using PHP or ASP, Tom Muck has a free horizontal looper extension that you can obtain from here: http://www.tom-muck.com/extensions/help/horizontallooper/.

Known Participant
July 12, 2012

I bougt the horizontal vertical looper PHP from Tom Muck and got i to work here

Now I can't figure out how to insert a playerID (hidden field id) and a drillID (the loop) in a lookup table "exercise_spelare_ref" where I have 3 columns:

id drillID kommentar

21 32 NULL

21 34 NULL

21 47 NULL

35 31 NULL

35 33 NULL

I think I want it this way instead of comma separated, not sure why though

id and drillID are composite index kommentar is for later use (problems :-) a possibility to comment on every drill on a player level (id)

I understand that I should make a foreeach loop and end the checkbox name with [] to make an array maybe even the hidden field id, not sure.

With the standard Dreamweaver insert record I can only insert the last choosen checkbox along with the id.

Code here:

<?php
if(!isset($tfm_rows) || intval($tfm_rows) == 0){$tfm_rows = -1;}
if(!isset($tfm_columns) || intval($tfm_columns) == 0){$tfm_columns = 4;}
if(!isset($tfm_vertical)){$tfm_vertical = "true";}
?>
<?php  require_once('../dirName/fileName.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO exercise_spelare_ref (id, drillID) VALUES (%s, %s)",
                       GetSQLValueString($_POST['spelareID'], "text"),
                       GetSQLValueString($_POST['drillSelect'], "text"));

  mysql_select_db($database_connect, $connect);
  $Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());
}

// Horizontal looper block 1 -- set up array, row and column values
$HLoop_Recordset1 = array();
$HLoop_Recordset1_rows = $tfm_rows;
$HLoop_Recordset1_columns = $tfm_columns;
$HLoop_Recordset1_vertical = $tfm_vertical;

if($HLoop_Recordset1_vertical == "true") {
$HLoop_Recordset1_loopTo = $HLoop_Recordset1_rows;
}else{
$HLoop_Recordset1_loopTo = $HLoop_Recordset1_columns;
}
$HLoop_Recordset1_i = 0;
$HLoop_Recordset1_ii = 0;
$HLoop_Recordset1_actualrows = 1;

mysql_select_db($database_connect, $connect);
$query_Recordset1 = "SELECT * FROM exercise";
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$colname_rsSpelare = "-1";
if (isset($_GET['id'])) {
  $colname_rsSpelare = $_GET['id'];
}
mysql_select_db($database_connect, $connect);
$query_rsSpelare = sprintf("SELECT id, user_login, first_name, last_name FROM analys_kund WHERE id = %s", GetSQLValueString($colname_rsSpelare, "int"));
$rsSpelare = mysql_query($query_rsSpelare, $connect) or die(mysql_error());
$row_rsSpelare = mysql_fetch_assoc($rsSpelare);
$totalRows_rsSpelare = mysql_num_rows($rsSpelare);

mysql_select_db($database_connect, $connect);
$query_rsRef = "SELECT * FROM exercise_spelare_ref";
$rsRef = mysql_query($query_rsRef, $connect) or die(mysql_error());
$row_rsRef = mysql_fetch_assoc($rsRef);
$totalRows_rsRef = mysql_num_rows($rsRef);
$query_Recordset1 = "SELECT drillID, categori, rubrik FROM exercise";
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

if ($HLoop_Recordset1_rows < 1){
$HLoop_Recordset1_rows = ceil($totalRows_Recordset1 / $HLoop_Recordset1_columns);
if($HLoop_Recordset1_loopTo < 1) {
  $HLoop_Recordset1_loopTo = $HLoop_Recordset1_rows;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Välj Övningar</title>
</head>

<body>
<strong>Spelare: <?php echo $row_rsSpelare['first_name']; ?>  <?php echo $row_rsSpelare['last_name']; ?></strong><br />
<br />
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <?php
// Horizontal Looper start code for Recordset1

do {
ob_start();
?>
    <input type="checkbox" name="drillSelect" value="<?php echo $row_Recordset1['drillID']; ?>" id="drillSelect" />
    <?php echo $row_Recordset1['rubrik']; ?>
    </label>
    <?php
// HLooper manage the arrays for Recordset1
$HLoop_Recordset1_temp = ob_get_contents(); //dump buffer to variable
ob_end_clean(); //clear buffer
$HLoop_Recordset1[$HLoop_Recordset1_i][$HLoop_Recordset1_ii] = $HLoop_Recordset1_temp;
$HLoop_Recordset1_ii++;
if($HLoop_Recordset1_ii >= $HLoop_Recordset1_loopTo){
$HLoop_Recordset1_i++;
$HLoop_Recordset1_ii = 0;
$HLoop_Recordset1_actualrows++;
};
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
if($HLoop_Recordset1_actualrows < $HLoop_Recordset1_rows && $HLoop_Recordset1_vertical == "false") $HLoop_Recordset1_rows = $HLoop_Recordset1_actualrows;
if($HLoop_Recordset1_actualrows < $HLoop_Recordset1_columns && $HLoop_Recordset1_vertical == "true") $HLoop_Recordset1_columns = $HLoop_Recordset1_actualrows;

?>
  <table class="hloop">
    <?php for($i = 0; $i < $HLoop_Recordset1_rows; $i++) { ?>
    <tr>
      <?php for($ii = 0; $ii < $HLoop_Recordset1_columns; $ii++) { ?>
      <td><?php
            if($HLoop_Recordset1_vertical == "true") {
              echo(isset($HLoop_Recordset1[$ii][$i]) ? $HLoop_Recordset1[$ii][$i] : " ");
             }else{
              echo(isset($HLoop_Recordset1[$i][$ii]) ? $HLoop_Recordset1[$i][$ii] : " ");
            } ?></td>
      <?php } ?>
    </tr>
    <?php } // End Horizontal/Vertical Looper code for Recordset1 ?>
  </table>
  <input name="spelareID" type="hidden" value="<?php echo $row_rsSpelare['id']; ?>" />
  <input type="hidden" name="MM_insert" value="form1" />
  <input type="submit" name="submit" id="submit" value="Välj övningar" />
</form>
<p>
</p>

</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($rsSpelare);

mysql_free_result($rsRef);
?>

Thank's in advance

Willy

David_Powers
Inspiring
July 12, 2012

Have you tried contacting Tom Muck to see if he has a solution?

David_Powers
Inspiring
July 7, 2012

Please don't add a new question to a 3-year-old thread. I have branched this into a separate thread of its own.