Results 1 to 3 of 3

Thread: How to generate a users choice table

  1. #1
    Join Date
    Apr 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to generate a users choice table

    I am attempting to create a table that consists of 2 forms where the first form gets info from the second. so i have table1 and table 2. I want to make it to be users choice . a user picks the number of rows and columns(I went up to 7 rows and columns in dropbox) and color from a drop down box and whatever they pick it generates. My problem is when I select something instead of showing me a table row and columns with the colors its showing me 1111 can anyone suggest something? Maybe my logic is wrong please help.
    Code:
    ?php
    $color= substr(filter_input(INPUT_GET,'color',FILTER_SANITIZE_NUMBER_INT),0,10);
    ?>
    <!DOCTYPE html>
    <html>
     <head>
    	<meta charset="UTF-8">
    	<meta name="keywords" content="Table">
    	<meta name="description" content="table Creator">
    	<link rel="stylesheet" type="text/css" href="style.css">
    	<style>
    		tr:nth-child(even)		{ 
    				background-color:#000000; 
    				color:#000000; 
    				<?php
    				echo $color
    				?>;
    			}
    		table, th, td {
    			border: 1px solid #000000; ;
    			padding: 10px;
    		}
    		table {
    			border-collapse: collapse;
    		}
    	</style>
    	
    	<title>table</title>
    	
    	
    </head>
    
    <body>
       <header>
    			<h1> Projects</h1>
    		</header>
    	
    
    <nav>
    	
    </nav>
    
    <section>
    	
      <h2> Table Creator</h2>
      
    
      
      <?php
      $rows= substr(filter_input(INPUT_GET,'rows',FILTER_SANITIZE_NUMBER_INT),0,3);
      $cols= substr(filter_input(INPUT_GET,'cols',FILTER_SANITIZE_NUMBER_INT),0,3);
     
      
      echo "<Table>";
       
      
      for ($x=1; $x<=$rows; $x++)
      {
    	  
    	  echo "<tr>";
    	  for ($y=1; $y<=$cols; $y++)
      
        echo  "<td>$rows $x $cols $y</td>";
       }
      
      {
    	 echo "<tr>";
      }
     
     echo "</Table>";
       
     
     
      
      ?>
      
      
    </section>
    
    <footer>
    	
    </footer>
    
    <p></p>
    
    </body>
    </html>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Works OK here, the color logic seems flawed. I called mine user_choice_h.php and used this url:

    user_choice_h.php?color=ff0012&rows=3&cols=4

    Now the trouble with color is at least twofold. One, it's filtering for an integer, so ff and other higher hex digits get stripped. Even if the hex value made it through, the way it is written out in the code in the style section doesn't result in a valid color declaration.

    The rest seemed fine (click image to see result).

    Click image for larger version. 

Name:	user_choice.jpg 
Views:	120 
Size:	10.4 KB 
ID:	5889
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    The PHP function ctype_xdigit($string) will check that every character in $string is an hex digit and return a boolean TRUE or FALSE. It doesn't alter the string in any way.

    That might be useful.

Similar Threads

  1. Replies: 0
    Last Post: 12-05-2013, 08:04 PM
  2. Sql table for users online help
    By keyboard in forum PHP
    Replies: 3
    Last Post: 09-22-2011, 12:45 AM
  3. PhP auto generate table
    By Douglas879 in forum PHP
    Replies: 2
    Last Post: 11-29-2010, 11:16 AM
  4. PhP auto generate table
    By neo_philiac in forum PHP
    Replies: 5
    Last Post: 10-29-2010, 08:07 PM
  5. get users name from id in another table
    By queerfm in forum PHP
    Replies: 2
    Last Post: 04-22-2009, 10:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •