三栏人口

时间:2014-04-07 22:17:49

标签: php sql

所以,我从其他人手中接过了一个项目,我试图在一个表中填充三列,其中有两列。我几乎把事情搞清楚了,但是我的第三个专栏却无法完成。我已经得到它所以它将数据分成三分之一,但只有左列实际上只有三分之一的数据。中间列有另外三分之二的数据,右列没有数据。

这是我正在使用的代码。但是,我已经改变了我们生产的东西"东西"并出于隐私原因遗漏了网址:

    $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>';

我知道这与&#34;&#34;之后的所有事情有关。编码,但由于我不以此为生,我不知道需要什么编码来填充我的三列。 请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这个...它应该对你有用...之前使用过这个逻辑并运作良好:

<?php

   $iUp = 1;

    $pQuery = mysql_query($query) or die(mysql_error());
    $pExist = mysql_num_rows($pQuery);

    if(!empty($pExist)){

        $this->stuffPackageOut .= '<input type="hidden" name="cart!addFamily">';

        $pCnt = $pExist;
        $pCntHalf = floor($pCnt/3);


        while($pRow = mysql_fetch_object($pQuery)){
            $contribName = strtolower(str_replace(" ", "", $pRow->conName));
            $stuffName = strtolower(str_replace(" ", "", $pRow->stfName));

            if($iUp <= $pCntHalf){
            $stuff_left_a .= '<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>';          
            }
            elseif($iUp >= $pCntHalf +1 && $iUp <= ($pCntHalf * 2)){
            $stuff_middle_a .= '<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>';
            }
            elseif($iUp >= ($pCntHalf *2) +1){
            $stuff_right_a .= '<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_left_a;
        $stuffLeft .= '</table>';

        $stuffMiddle  = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
        $stuffMiddle .= $stuff_middle_a;
        $stuffMiddle .= '</table>';

        $stuffRight  = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
        $stuffRight .= $stuff_right_a;
        $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>';

?>

我发现了错误......这是我在中间的数学...注意到变化:

elseif($iUp >= $pCntHalf +1 && $iUp <= ($pCntHalf * 2))