Jump to content

[SOLVED] Form Table help


psychowolvesbane

Recommended Posts

Okay I got this code that places each record from the table Colours (1 field called AvailableColours) and palces those records in an array.

 

What I have below displays a table with each odd row with an image with the same name as the array value and a row of check buttons underneath each one that have matching names. However this ends up displaying every record in a single line as so:

 

http://i110.photobucket.com/albums/n82/psychofox19/example1.jpg

 

But I want it to look like this:

 

http://i110.photobucket.com/albums/n82/psychofox19/example2.jpg (Example done manually)

 

Can anyone help with the coding?

 

<?php
//Establish a connection to the Database

$conn = mysql_connect('$host','$username','$password');

//Select the MySQL database

$db = mysql_select_db('$dbname', $conn);

//Issue SQL SELECT Statement
$sql = "SELECT AvailableColours FROM Colours ORDER BY AvailableColours";
  
//Execute the SQL Statement and create a recordset
$rs = mysql_query($sql, $conn) or die(mysql_error());

$NumberOfColours = mysql_num_rows($rs);

while($row = mysql_fetch_array($rs))
{
   $Colour[] = $row[AvailableColours];
}

$X=0;
?>

<fieldset style="padding: 2">
<legend>Available Colours</legend>
<table border="1" id="Colours">
  <tr>

  <?php
  if($NumberOfColours<18)
  {
     while($X<17)
     {
         echo"<td><img src='/images/colours/$Colour[$X].gif' width='25' height='25' alt='$Colour[$X]'></td>";
     
        $X=$X+1;
     }
     $X=0;
     ?>
     </tr>
     <tr>
     <?php
     
     while($X<17)
     { 
        echo"<td><input type='checkbox' name='$Colour[$X]' value='ON'></td>";
     
        $X=$X+1;
     }
  }
  else
  {  
     while($X<$NumberOfColours)
     {
        echo"<td><img src='/images/colours/$Colour[$X].gif' width='25' height='25' alt='$Colour[$X]'></td>";
     
        $X=$X+1;
     }
     $X=0;
     ?>
    </tr>
    <tr>
    <?php
    while($X<$NumberOfColours)
    {
       echo"<td><input type='checkbox' name='$Colour[$X]' value='ON'></td>";
     
       $X=$X+1;
    }
  }
  ?>
  </tr>
<table>
</legend>
</fieldset>

Link to comment
https://forums.phpfreaks.com/topic/84670-solved-form-table-help/
Share on other sites

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.