psychowolvesbane Posted January 2, 2008 Share Posted January 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/ Share on other sites More sharing options...
MadTechie Posted January 2, 2008 Share Posted January 2, 2008 you lost me.. so i read the code now i am even more confused whats with the numberofcolours.. <?php $NumberOfColours = mysql_num_rows($rs); //....snip while(X <= $NumberOfColours) { $X = mysql_num_rows($rs) ?> Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428406 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 The number of colours in the table field, so i'm using that as a Max Number variable. Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428407 Share on other sites More sharing options...
MadTechie Posted January 2, 2008 Share Posted January 2, 2008 Erm.. not really! your using it to loop once!... but you also have some inf. loops (if they loop) also <?php echo'$Colour'?> will not work should be <?php echo $Colour; ?> are you trying to build a table from the database records ? Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428409 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 Yes, but I only know how it looks not how I'm going to do it Table should be 17 columns wide, odd rows should be pictures, and even rows should be check buttons. Check Button 1 should be under Pic 1 and should have the same name as record 1 and so on. Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428411 Share on other sites More sharing options...
MadTechie Posted January 2, 2008 Share Posted January 2, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428420 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428454 Share on other sites More sharing options...
MadTechie Posted January 2, 2008 Share Posted January 2, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428462 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 No it still looks the same http://psychowolvesbane.freehostia.com/admin/add_product_form.php Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428476 Share on other sites More sharing options...
MadTechie Posted January 2, 2008 Share Posted January 2, 2008 can you post the code you have Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428488 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 $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> Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428490 Share on other sites More sharing options...
MadTechie Posted January 2, 2008 Share Posted January 2, 2008 is this needed ? echo "<tr>\n"; echo "<td width=\"100%\"></td>\n"; echo "</tr>\n"; if not remove it Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428499 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428505 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 I want it to look like this eventually: http://psychowolvesbane.freehostia.com/admin/orders.htm Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428511 Share on other sites More sharing options...
MadTechie Posted January 2, 2008 Share Posted January 2, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428522 Share on other sites More sharing options...
psychowolvesbane Posted January 2, 2008 Author Share Posted January 2, 2008 Is it possible to have a slight more padding between each pair of rows? Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-428585 Share on other sites More sharing options...
psychowolvesbane Posted January 3, 2008 Author Share Posted January 3, 2008 Hey MadTechie have you come up with anything yet? Quote Link to comment https://forums.phpfreaks.com/topic/84156-solved-form-table-help/#findComment-429405 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.