Reply
Help with checkbox code
Old 09-23-2005, 07:29 AM Help with checkbox code
Junior Talker

Posts: 2
Hi,
I hope I'm posting in the right place ... first time here.
I have this code from a classifieds program that creates checkboxes and there are 2 problems that are beyond me to fix.

1) This code inserts a blank box and I think it is to clear the mysql field of contents but I'm only guessing but the results look silly with a box doing nothing.

2) I want 2 have the results in columns and I've fiddled and fiddled but got nowhere.

Can anyone help me out? as the programmer of the script is a waste of time he just doesn't reply.


Code:
 if ($type == 'c')
 {  
  	$i = 0;
  	$num_options = 0;
  	$c = 0;
  	$filled_in = 0;
  	
  	//print_r($value);
  	if (file_exists("admin/options/$nb". ".txt"))
  	{
  	$options = file("admin/options/$nb". ".txt");
      $num_options =  count($options);
      global $la_empty;
      print "<input type='checkbox' value='empty' name='$fieldname" . "[]'>&nbsp;<br>";
     
      for ($i=1; $i<$num_options; $i++)
    	{
      print "<input type='checkbox' value='" . $i ."' name='$fieldname" . "[]'";
      if (is_array($value))
      {
      	foreach ($value as $element)
      	{
        if ($element == $i)
        print " checked='checked'";
      	}
      }
      print " />$options[$i]";
        print "&nbsp;&nbsp;&nbsp;<br />";
      }
      
  }
    else 
    	print "You have not provided any options from admin area.";	
    
 }
Rackspace is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 09-30-2005, 02:49 AM
ScriptReference's Avatar
Average Talker

Posts: 25
Location: Reno, NV
This will produce some nicely formatted table-based output. The extra checkbox at the top has been commented out and a table introduced to create 2 columns. Additionally, the original code was discarding the first entry in your text file. This code does not discard that entry. Other variables not used in this part of the code (i.e. $c, $filled_in, and $la_empty) have been left even though they serve no purpose in this setting since you may have cleaned up the code for your question here. If not, feel free to comment them out.

Code:
if ($type == 'c')
 {  
  	$i = 0;
  	$num_options = 0;
  	$c = 0;
  	$filled_in = 0;
  	
  	//print_r($value);
  	if (file_exists("admin/options/$nb". ".txt"))
  	{
  	  $options = file("admin/options/$nb". ".txt");
      $num_options =  count($options);
      global $la_empty;
      
      //This line put the empty box at the top.
      //print "<input type='checkbox' value='empty' name='$fieldname" . "[]'>&nbsp;<br>";
      
      //For 2 columns, we'll use a table.
      print "<table>\n";
      
      for ($i=0; $i<$num_options; $i++)
    	{
      	if ($i%2 == 0) print "\t<tr>\n"; //Start of row (when $i is zero or even)
        print "\t\t<td><input type='checkbox' value='" . $i ."' name='$fieldname" . "[]'";
        if (is_array($value))
        {
        	foreach ($value as $element)
        	{
            if ($element == $i)
              print " checked='checked'";
        	}
        }
        print " />".trim($options[$i])."</td>\n";
        //print "&nbsp;&nbsp;&nbsp;<br />";
        if ($i%2 == 1) print "\t</tr>\n"; //End of row (when $i is an odd number)
      }
      if ($i%2 == 1) print "\t</tr>\n"; //End row which wasn't already closed
      print "</table>";
      
    }
    else 
    	print "You have not provided any options from admin area.";	
 }
ScriptReference is offline
Reply With Quote
View Public Profile Visit ScriptReference's homepage!
 
Old 10-04-2005, 03:31 PM
Junior Talker

Posts: 2
Hi,
thanks for that I like the way it has 2 columns but I still have the spare blank box at the start

Making my head hurt
Rackspace is offline
Reply With Quote
View Public Profile
 
Old 10-04-2005, 03:54 PM
ScriptReference's Avatar
Average Talker

Posts: 25
Location: Reno, NV
This line
Code:
 //This line put the empty box at the top.
 //print "<input type='checkbox' value='empty' name='$fieldname" . "[]'>&nbsp;<br>";
removed the extra box. The only other way it would have an extra line is if your text file had a blank at the top.
ScriptReference is offline
Reply With Quote
View Public Profile Visit ScriptReference's homepage!
 
Reply     « Reply to Help with checkbox code
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12274 seconds with 12 queries