CincoPistolero Posted July 10, 2009 Share Posted July 10, 2009 I have some code that pulls records out of a db and list those records next to checkboxes in two columns. The code checks another table to see if the checkbox should be checked. Everything displays perfect if atleast one checkbox is checked. However, if non have yet to be checked it breaks my html table. I want it like this(and it is if a box is checked) []opt1 []opt2 []opt3 []opt4 It looks like this(if no box has been checked []opt1 []opt2 []opt3 []opt4 []opt5 - etc Below is the current code <td colspan="2"> <!-- <table> --> <?php $max2=2; $query2="SELECT op.optPricesID, o.name, op.basePrice, IF(op.optPricesID IN (SELECT optPricesID FROM woUpg WHERE awoID='$awoID'),1,0) as checked FROM optPrices op, options o WHERE op.optionID = o.optionID AND op.drumTypeID=1"; $result2=mysql_query($query2); $num2=mysql_num_rows($result2); if(empty($num2)){ $final2="\t<tr><td width='720'><center><span class='optTitles'>Nothing to Display</span></center></td></tr>\n"; }else{ while($row2=mysql_fetch_array($result2,MYSQL_NUM)){ if($row2[3]!=0) { $array2[]="<input type=checkbox name='btOptI[]' value='".$row2[0]."' checked> ".$row2[1]; }else { $array2[]="<input type=checkbox name='btOptI[]' value='".$row2[0]."'> ".$row2[1]; } } mysql_free_result($result2); $final2="<tr>\n"; foreach($array2 as $thumbnail2){ if($counter2==$max2){ $counter2=1; $final2.="\n<tr>\n"; }else $counter2++; $final2.="\t<td align=\"left\" width=\"350\" height=\"20\"><span class='optTitles'>".$thumbnail2."</span></td>\n"; } if($counter2){ if($max2-$counter2){ $final2 .= "\t<td width=\"350\" height=\"20\"> </td>\n"; } $final2.="</tr>"; } } echo " $final2"; ?> <!-- </table> --> </td> an even weirder(is this a word) part is this, my set up is like below <tr><td> php code above is here</td></tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" align="right" class="bold">BASS/KICK UPGRADES TOTAL: $<?php echo $bkuTotal; ?></td> </tr> the two rows above get put in with the table in the row that contains all the code above if I try to contain that code within a table. So if I put table tags around the php code above, I'll get my columns, but the blank line goes away and the right aligned TOTAL line goes to the left and is not bold. I may have just been looking at this for too long. Once again, I need the code to display in two columns whether a box is checked or not, and I want those last two rows to display as stated. Quote Link to comment https://forums.phpfreaks.com/topic/165537-solved-displaying-two-columns-of-checkboxes/ Share on other sites More sharing options...
CincoPistolero Posted July 13, 2009 Author Share Posted July 13, 2009 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/165537-solved-displaying-two-columns-of-checkboxes/#findComment-874859 Share on other sites More sharing options...
haku Posted July 14, 2009 Share Posted July 14, 2009 Run your script, and copy the generated source to this thread. It will be easier to see where the problem is if we can see what it looks like when it's not working the way you want. Quote Link to comment https://forums.phpfreaks.com/topic/165537-solved-displaying-two-columns-of-checkboxes/#findComment-874978 Share on other sites More sharing options...
CincoPistolero Posted July 15, 2009 Author Share Posted July 15, 2009 Below is what I get from view source after loading my page. In this example I've added table tags. This allows all columns to display correctly, however, the last two rows, one being a blank line, the other being a right aligned price row do not work, its as if those two row tags are ignored and the blank line is gone and the price row is just added to the end of the columns. If I remove the table tags, the columns break if nothing is selected and those last two rows work. <!-------------------------Bass/Kick/Tom Options---------------------------------------> <div id="bkOpt"> <table width="720" cellpadding="0" cellspacing="0" border="0"> <tr> <td colspan="2"><h3>Tom/Bass/Kick Drum Options</h3></td> </tr> <tr> <td valign="top" colspan="2" align="left" width="100%" class="r3">Tom/Bass Upgrades</td> </tr> <tr> <td>No Upgrades Chosen</td> </tr> </table> </tr> <tr> <td colspan="2"><hr></td> </tr> <!- ---------------- Tom/Bass Upgrade Options -------------------------------- -> <tr> <td colspan="2"> <!-- <table> --> <table><tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='67'> Custom Brass Head Logo/Artwork</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='66'> HOLZ Bass Head Ports (2"/4"/6" & Oval)</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='65'> Aquarian Bass Head</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='64'> Aquarian Tom Head</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='63'> Gibraltar Bracket</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='62'> DW TB12 Bracket</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='61'> STANDARD Floor Cradle</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='60'> STANDARD Hanging Mount</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='59'> Gauger Floor Cradle</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='58'> Gauger Hanging Tom Mount</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='57'> Chop Block</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='56'> Yamaha-Style Wood Hoops</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='55'> Vintage Claw-Style Wood Hoops</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='54'> Diecast Hoops</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='53'> Powder Coating</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='52'> Offset Lug Placement</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='51'> Upgrade 3 Lugs</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='50'> Upgrade 2 Lugs</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='49'> Tube Lugs</span></td> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='48'> Reinforcement Rings (6/8/10-PLY)</span></td> <tr> <td align="left" width="350" height="20"><span class='optTitles'><input type=checkbox name='btOptI[]' value='69'> 10-PLY Shell Upgrade</span></td> <td width="350" height="20"> </td> </tr></table> <!-- </table> --> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" align="right" class="bold">BASS/KICK UPGRADES TOTAL: $0</td> </tr> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/165537-solved-displaying-two-columns-of-checkboxes/#findComment-875783 Share on other sites More sharing options...
J.Daniels Posted July 15, 2009 Share Posted July 15, 2009 This may be the start of your problem. <div id="bkOpt"> <table width="720" cellpadding="0" cellspacing="0" border="0"> <tr> <td colspan="2"><h3>Tom/Bass/Kick Drum Options</h3></td> </tr> <tr> <td valign="top" colspan="2" align="left" width="100%" class="r3">Tom/Bass Upgrades</td> </tr> <tr> <td>No Upgrades Chosen</td> </tr> </table> </tr> You have an opening div, a full table, then a closing </tr>. If I change it to: <div id="bkOpt"> <table width="720" cellpadding="0" cellspacing="0" border="0"> <tr> <td colspan="2"><h3>Tom/Bass/Kick Drum Options</h3></td> </tr> <tr> <td valign="top" colspan="2" align="left" width="100%" class="r3">Tom/Bass Upgrades</td> </tr> <tr> <td>No Upgrades Chosen</td> </tr> </table> <table> then it works as expected. Try validating your code through the W3C validator. Quote Link to comment https://forums.phpfreaks.com/topic/165537-solved-displaying-two-columns-of-checkboxes/#findComment-875810 Share on other sites More sharing options...
CincoPistolero Posted July 15, 2009 Author Share Posted July 15, 2009 BAM!!!! I knew I had been looking at this for too long. SOLVED!!! 'Twas html tags not php. Quote Link to comment https://forums.phpfreaks.com/topic/165537-solved-displaying-two-columns-of-checkboxes/#findComment-875986 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.