Jump to content

[SOLVED] Form Table help


psychowolvesbane

Recommended Posts

Hello I am trying to display on a form a table that contains 2 main rows, 1 for each different Colour (referenced by an image in a different directory) and a corresponding Check Box.

 

What I have been trying to do is first of all is select the information from the database (a single field called Colours), then for each record place an image inside a cell of a table until there are 17 cells, then on the 2nd row place a Check Box which has a corresponding name to the Colour record until 17 cells have also been entered. Since there will be more than 17 records I want to repeat the process on rows 3 and 4 and so on until all records have been added to the table.

 

This is what I have so far:

 

<fieldset style="padding: 2">
<legend>Available Colours</legend>

<?php
//Establish a connection to the Database

$conn = mysql_connect('mysql2.freehostia.com:3306','adacom_CLine','clothingline');

//Select the MySQL database

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

$string = $_POST['ClothingCode'];

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

$NumberOfColours = mysql_num_rows($rs);
  
//Loop through the recordset and display the necessary records
while($row = mysql_fetch_array($rs))
{

$Colour = $row['Colour'];

?>

<table border="1" id="Colours" cellpadding="3">

<?php

   while(X <= $NumberOfColours)
   {
    $X = mysql_num_rows($rs)  
      
      while($Y<= "17")   
      {   
?>
        <tr>
   <td width="25">
      <img border="0" src="../images/colours/<?php echo'$Colour'?>.gif" width="25" height="25" alt="<?php echo '$Colour'?>">
           </td>
</tr>
      
      
      <?php
      }
      
      while($Y<="17")
      {
 ?>    
         <tr>
    <td width="25"><input type="checkbox" name="<?php echo '$Colour'?>" value="ON"></td>
 </tr>
         <?php
      }
      
      ?>
      <tr>
        <td width="100%"></td>
      </tr>

      <?php   

      $Y = $Y+1;
   }
   
}

mysql_close($conn);
?>

</table>

</fieldset>

 

I want it to repeat it for each record, for each row group (Pic and Check Button), and for each Pic Row and Check Button Row in the previous loop.

 

Can anyone help?

Link to comment
Share on other sites

okay try this

 

<fieldset style="padding: 2">
<legend>Available Colours</legend>

<?php
//Establish a connection to the Database

$conn = mysql_connect('mysql2.freehostia.com:3306','adacom_CLine','clothingline');

//Select the MySQL database

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

$string = $_POST['ClothingCode'];

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

$NumberOfColours = mysql_num_rows($rs);
  
echo "<table border=\"1\" id=\"Colours\" cellpadding=\"3\">\n";
$odd = true;
//Loop through the recordset and display the necessary records
while($row = mysql_fetch_array($rs))
{
$Colour = $row['Colour'];
if($odd)
{
	echo "<tr>\n";
	echo "	<td width=\"25\">";
	echo "		<img border=\"0\" src=\"../images/colours/$Colour.gif\" width=\"25\" height=\"25\" alt=\"$Colour\">\n";
	echo "	</td>";
	echo "</tr>";
}else{
	echo "<tr>";
	echo "	<td width=\"25\">\n";
	echo "		<input type=\"checkbox\" name=\"$Colour\" value=\"ON\">\n";
	echo "	</td>";
	echo "</tr>";
}
echo "<tr>\n";
echo "<td width=\"100%\"></td>\n";
echo "</tr>\n"; 
$odd = !$odd;
}

mysql_close($conn);
?>

</table>

</fieldset>

Link to comment
Share on other sites

This is what it looks like:

 

http://psychowolvesbane.freehostia.com/admin/add_product_form.php

 

It's sending it all into the same column.

 

<fieldset style="padding: 2">
<legend>Available Colours</legend>

<?php
//Establish a connection to the Database

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

//Select the MySQL database

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

$string = $_POST['ClothingCode'];

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

$NumberOfColours = mysql_num_rows($rs);
  
echo "<table border=\"1\" id=\"Colours\" cellpadding=\"3\">\n";
//Loop through the recordset and display the necessary records
while($row = mysql_fetch_array($rs))
{
$Colour = $row['Colour'];

echo "<tr>\n";
echo "	<td width=\"25\">";
echo "		<img border=\"0\" src=\"../images/colours/<?php echo '$Colour'?>.gif\" width=\"25\" height=\"25\" alt=\"$Colour\">\n";
echo "	</td>";
echo "</tr>";
echo "<tr>";
echo "	<td width=\"25\">\n";
echo "		<input type=\"checkbox\" name=\"$Colour\" value=\"ON\">\n";
echo "	</td>";
echo "</tr>";
echo "<tr>\n";
echo "<td width=\"100%\"></td>\n";
echo "</tr>\n";  
}

mysql_close($conn);
?>

</table>

</fieldset>

Link to comment
Share on other sites

your not using the code i pasted.. but i see what your doing

<fieldset style="padding: 2">
<legend>Available Colours</legend>

<?php
//Establish a connection to the Database

$conn = mysql_connect('mysql2.freehostia.com:3306','adacom_CLine','clothingline');

//Select the MySQL database

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

$string = $_POST['ClothingCode'];

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

$NumberOfColours = mysql_num_rows($rs);
  
echo "<table border=\"1\" id=\"Colours\" cellpadding=\"3\">\n";
$odd = true;
$counter = 17;
$c = 0;
//Loop through the recordset and display the necessary records
while($row = mysql_fetch_array($rs))
{
$Colour = $row['Colour'];
if($c == 0) echo "<tr>\n";
if($odd)
{
	echo "	<td width=\"25\">";
	echo "		<img border=\"0\" src=\"../images/colours/$Colour.gif\" width=\"25\" height=\"25\" alt=\"$Colour\">\n";
	echo "	</td>";
}else{
	echo "	<td width=\"25\">\n";
	echo "		<input type=\"checkbox\" name=\"$Colour\" value=\"ON\">\n";
	echo "	</td>";
}
if($c == 0)
{
	echo "</tr>";
	$c = $counter;
}else{
	$c--;
}
echo "<tr>\n";
echo "<td width=\"100%\"></td>\n";
echo "</tr>\n"; 
$odd = !$odd;
}

mysql_close($conn);
?>

</table>

</fieldset>

Link to comment
Share on other sites

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

$NumberOfColours = mysql_num_rows($rs);
  
echo "<table border=\"1\" id=\"Colours\" cellpadding=\"3\">\n";
$odd = true;
$counter = 17;
$c = 0;
//Loop through the recordset and display the necessary records
while($row = mysql_fetch_array($rs))
{
$Colour = $row['Colour'];
if($c == 0) echo "<tr>\n";
if($odd)
{
	echo "	<td width=\"25\">";
	echo "		<img border=\"0\" src=\"../images/colours/$Colour.gif\" width=\"25\" height=\"25\" alt=\"$Colour\">\n";
	echo "	</td>";
}else{
	echo "	<td width=\"25\">\n";
	echo "		<input type=\"checkbox\" name=\"$Colour\" value=\"ON\">\n";
	echo "	</td>";
}
if($c == 0)
{
	echo "</tr>";
	$c = $counter;
}else{
	$c--;
}
echo "<tr>\n";
echo "<td width=\"100%\"></td>\n";
echo "</tr>\n"; 
$odd = !$odd;
}

mysql_close($conn);
?>

</table>

</fieldset>

Link to comment
Share on other sites

Okay that looks better http://psychowolvesbane.freehostia.com/admin/add_product_form.php

 

The code for that is:

 


<fieldset style="padding: 2">
<legend>Available Colours</legend>

<?php
//Establish a connection to the Database

$conn = mysql_connect('mysql2.freehostia.com:3306','adacom_CLine','clothingline');

//Select the MySQL database

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

$string = $_POST['ClothingCode'];

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

$NumberOfColours = mysql_num_rows($rs);
  
echo "<table border=\"1\" id=\"Colours\" cellpadding=\"3\">\n";
$odd = true;
$counter = 17;
$c = 0;
//Loop through the recordset and display the necessary records
while($row = mysql_fetch_array($rs))
{
$Colour = $row['Colour'];
if($c == 0) echo "<tr>\n";
if($odd)
{
	echo "	<td width=\"25\">";
	echo "		<img border=\"0\" src=\"../images/colours/$Colour.gif\" width=\"25\" height=\"25\" alt=\"$Colour\">\n";
	echo "	</td>";
}else{
	echo "	<td width=\"25\">\n";
	echo "		<input type=\"checkbox\" name=\"$Colour\" value=\"ON\">\n";
	echo "	</td>";
}
if($c == 0)
{
	echo "</tr>";
	$c = $counter;
}else{
	$c--;
}

$odd = !$odd;
}

mysql_close($conn);
?>

</table>

</fieldset>

 

Link to comment
Share on other sites

Okay i got dinner will be back

 

quick update

 

<fieldset style="padding: 2">
<legend>Available Colours</legend>

<?php
//Establish a connection to the Database

$conn = mysql_connect('mysql2.freehostia.com:3306','adacom_CLine','clothingline');

//Select the MySQL database

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

$string = $_POST['ClothingCode'];

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

$NumberOfColours = mysql_num_rows($rs);
  
echo "<table border=\"1\" id=\"Colours\" cellpadding=\"3\">\n";
$odd = true;
$counter = 17;
$c = $counter;
//Loop through the recordset and display the necessary records
while($row = mysql_fetch_array($rs))
{
$Colour = $row['Colour'];
if($c == $counter) echo "<tr>\n";
if($odd)
{
	echo "	<td width=\"25\">";
	echo "		<img border=\"0\" src=\"../images/colours/$Colour.gif\" width=\"25\" height=\"25\" alt=\"$Colour\">\n";
	echo "	</td>";
}else{
	echo "	<td width=\"25\">\n";
	echo "		<input type=\"checkbox\" name=\"$Colour\" value=\"ON\">\n";
	echo "	</td>";
}

if($c == 0)
{
	echo "</tr>";
	$c = $counter;
}else{
	$c--;
}
$odd = !$odd;
}

if($c != 0)  echo "</tr>";

mysql_close($conn);
?>

</table>

</fieldset>

 

but now i know what your looking for i know what do to (will a rework)

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.