Don't think I'll find that bit of code useful.
What I'm trying to achieve is really simple. I want to create a function where the one argument is the name of the input field. So for example if I want to create a list of checkboxes and would like the checkboxes to be named 'checkbox[]', I'd like the argument to act as such so that the checkboxes outputted would be part of the checkbox array.
Here's the heavily stripped down version of my function currently:
PHP Code:
function While_Loop($INPUT_TYPE, $NAME, $ID_COL, $ID_NAME, $FROM, $WHERE, $DIVISIBLE_BY, $VARIABLE_EQUAL_TO)
{
$QUERY = "SELECT $ID_COL AS id, $ID_NAME AS name FROM $FROM";
if($WHERE)
{
$QUERY = $QUERY . " WHERE $WHERE";
}
else
{
$QUERY = $QUERY . " ORDER BY $ID_COL DESC";
}
$RESULT = @mysql_query($QUERY);
if(@mysql_num_rows($RESULT) == 0)
{
echo "<font class='body'>None found!</font><P>";
}
else
{
$i=1;
if($INPUT_TYPE == "radio" OR $INPUT_TYPE == "checkbox")
{
echo "<table cellpadding='0' cellspacing='0'><tr>";
$NUM = divisible_by($i,$DIVISIBLE_BY);
while($ROW = mysql_fetch_array($RESULT))
{
if($INPUT_TYPE == "radio")
{
echo "<td><input type=\"$INPUT_TYPE\" name=\"$NAME\" value=\"$ROW[id]\"";
}
else($INPUT_TYPE == "checkbox")
{
// DON'T KNOW WHAT TO DO HERE!!!
//echo "<td><input type=\"$INPUT_TYPE\" name=\"$name\" value=\"$ROW[id]\"";
}
if($ROW[id] == $VARIABLE_EQUAL_TO)
{
echo " CHECKED";
}
echo "><font class='body'>$ROW[name]</font></td>";
if($NUM == 1)
{
echo "</tr><tr>";
}
$i++;
}
echo "</tr></table>";
}
elseif($INPUT_TYPE == "menu")
{
echo "<SELECT NAME='$NAME' SIZE='1'>";
while($ROW = mysql_fetch_array($RESULT))
{
echo "<OPTION VALUE=\"$ROW[id]\"";
if($ROW[id] == $VARIABLE_EQUAL_TO)
{
echo " SELECTED";
}
echo ">$ROW[name]</option>";
}
}
}
}
So if the below attained say 3 rows from the DB, then I would wish the checkboxes be named game[0], game[1] and game[2].
PHP Code:
echo $FORM->While_Loop("checkbox", "game", "ID_Game", "Game_Name", "tbl_games", "$where_clause", "1", "");
Appreciated.
Bookmarks