cosmosman Posted April 7, 2014 Share Posted April 7, 2014 So, I took over a project from someone else, and I am trying to populate three columns in a table where there was previously two columns. I've almost got things figured out, but can't quite get my third column to fill. I've got it so its separating the the data into thirds, but only the left column actually has exactly one third of the data. The middle column has the other two thirds of data, and the right column has no data. Here is the code I am working with. However, I've changed what we produce to "stuff" and left out the url for privacy reasons: $iUp = 1; $pQuery = mysql_query($query) or die(mysql_error()); $pExist = mysql_num_rows($pQuery); if(!empty($pExist)){ //$this->stuffPackageOut .= '<form action="https://*************.111/cart" method="GET" name="stuff" onsubmit="return anyCheck()">'; //$this->stuffPackageOut .= '<form action="index.php" method="GET" name="stuff" onsubmit="return anyCheck()">'; $this->stuffPackageOut .= '<input type="hidden" name="cart!addFamily">'; $pCnt = $pExist; $pCntHalf = floor($pCnt/3); $stuff[0] = NULL; $stuff[1] = NULL; $stuff[2] = NULL; $div = 0; while($pRow = mysql_fetch_object($pQuery)){ if($pCntHalf < $iUp){ $div = 2; $div = 1; }else{ $div = 0; } $contribName = strtolower(str_replace(" ", "", $pRow->conName)); $stuffName = strtolower(str_replace(" ", "", $pRow->stfName)); $stuff[$div] .= '<tr><td valign="top"><input type="checkbox" name="cart_family'.$iUp.'" value="'.$pRow->familyId.'" id="package"> <a href="http://****************.com/stuff/'.$stuffName.'.php" class="packagestufflinks">'.$pRow->fntName.'</td></tr>'; $iUp++; } $stuffLeft = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">'; $stuffLeft .= $stuff[0]; $stuffLeft .= '</table>'; $stuffMiddle = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">'; $stuffMiddle .= $stuff[1]; $stuffMiddle .= '</table>'; $stuffRight = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">'; $stuffRight .= $stuff[2]; $stuffRight .= '</table>'; $this->stuffPackageOut .= '<table width="100%" height="10"><tr><td align="left" valign="top" width="238" height="10">'.$stuffLeft.'</td><td width="29" valign="top" background="verticaldivider.gif"><img src="http://www.****************.com/pageimages/spacer.GIF" width="29" height="5"></td><td align="left" valign="top" width="238">'.$stuffMiddle.'<td><td width="29" valign="top" background="verticaldivider.gif"><img src="http://www.****************.com/pageimages/spacer.GIF" width="29" height="5"></td><td align="left" valign="top" width="238">'.$stuffRight.'</td></tr></table>'; I know it has something to do with everything following the "while" coding, but since I don't do this for a living I have no idea what coding is necessary to make my three columns populate.Please help me. Quote Link to comment https://forums.phpfreaks.com/topic/287597-populating-a-three-column-table/ Share on other sites More sharing options...
Ch0cu3r Posted April 8, 2014 Share Posted April 8, 2014 The problem is here if($pCntHalf < $iUp){ $div = 2; $div = 1; }else{ $div = 0; } $div = 1 is overriding $div = 2. In what order are you wanting to display the content? left to right?, eg 1 2 3 4 5 6 or down and left? 1 3 5 2 4 6 Quote Link to comment https://forums.phpfreaks.com/topic/287597-populating-a-three-column-table/#findComment-1475403 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.