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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.