Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无表三列类别布局_Php_Html - Fatal编程技术网

Php 无表三列类别布局

Php 无表三列类别布局,php,html,Php,Html,我正在处理一些代码,有点挂在某个片段上。希望能找到一些帮助。我正在使用开源WeBid拍卖脚本,并试图消除布局中使用的一些表。以下函数是相关代码 if (mysql_num_rows($result) == 0) { // redirect to global categories list header ('location: browse.php?id=0'); exit; } else { // Retrieve the translated category

我正在处理一些代码,有点挂在某个片段上。希望能找到一些帮助。我正在使用开源WeBid拍卖脚本,并试图消除布局中使用的一些表。以下函数是相关代码

if (mysql_num_rows($result) == 0)
{
    // redirect to global categories list
    header ('location: browse.php?id=0');
    exit;
}
else
{
    // Retrieve the translated category name
    $par_id = $category['parent_id'];
    $TPL_categories_string = '';
    $crumbs = $catscontrol->get_bread_crumbs($category['left_id'], $category['right_id']);
    for ($i = 0; $i < count($crumbs); $i++)
    {
        if ($crumbs[$i]['cat_id'] > 0)
        {
            if ($i > 0)
            {
                $TPL_categories_string .= ' &gt; ';
            }
            $TPL_categories_string .= '<a href="' . $system->SETTINGS['siteurl'] . 'browse.php?id=' . $crumbs[$i]['cat_id'] . '">' . $category_names[$crumbs[$i]['cat_id']] . '</a>';
        }
    }

    // get list of subcategories of this category
    $subcat_count = 0;
    $query = "SELECT * FROM " . $DBPrefix . "categories WHERE parent_id = " . $id . " ORDER BY cat_name";
    $result = mysql_query($query);
    $system->check_mysql($result, $query, __LINE__, __FILE__);
    $need_to_continue = 1;
    $cycle = 1;

    $TPL_main_value = '';
    while ($row = mysql_fetch_array($result))
    {
        ++$subcat_count;

        if ($cycle == 1)
        {
            $TPL_main_value .= '<tr align="left">' . "\n";

        }
        $sub_counter = $row['sub_counter'];
        $cat_counter = $row['counter'];
        if ($sub_counter != 0)
        {
            $count_string = ' (' . $sub_counter . ')';
        }
        else
        {
            if ($cat_counter != 0)
            {
                $count_string = ' (' . $cat_counter . ')';
            }
            else
            {
                $count_string = '';
            }
        }
        if ($row['cat_colour'] != '')
        {
            $BG = 'bgcolor=' . $row['cat_colour'];
        }
        else
        {
            $BG = '';
        }
        // Retrieve the translated category name
        $row['cat_name'] = $category_names[$row['cat_id']];
        $catimage = (!empty($row['cat_image'])) ? '<img src="' . $row['cat_image'] . '" border=0>' : '';
        $TPL_main_value .= "\t" . '<td ' . $BG . ' width="33%">' . $catimage . '<a href="' . $system->SETTINGS['siteurl'] . 'browse.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . $count_string . '</a></td>' . "\n";

        ++$cycle;
        if ($cycle == 4)
        {

            $cycle = 1;
            $TPL_main_value .= '</tr>' . "\n";
        }
    }

    if ($cycle >= 2 && $cycle <= 3)
    {
        while ($cycle < 4)
        {
            $TPL_main_value .= '    <td width="33%">&nbsp;</td>' . "\n";
            ++$cycle;

        }
        $TPL_main_value .= '</tr>' . "\n";
    }
if(mysql\u num\u行($result)==0)
{
//重定向到全局类别列表
标题('location:browse.php?id=0');
出口
}
其他的
{
//检索已翻译的类别名称
$par_id=$category['parent_id'];
$TPL_类别_字符串=“”;
$cramps=$catscoontrol->get_bread_cramps($category['left_id'],$category['right_id']);
对于($i=0;$i0)
{
如果($i>0)
{
$TPL_类别_字符串='';
}
$TPL_类别_字符串='';
}
}
//获取此类别的子类别列表
$subcat_count=0;
$query=“从“$DBPrefix.”类别中选择*,其中父项id=“.$id.”按类别名称排序”;
$result=mysql\u query($query);
$system->check_mysql($result、$query、\uuuuuu行、\uuuu文件);
$need_to_continue=1;
$cycle=1;
$TPL_main_值=“”;
while($row=mysql\u fetch\u数组($result))
{
++$subcat_计数;
如果($cycle==1)
{
$TPL\U主值=''。\n;
}
$sub_counter=$row['sub_counter'];
$cat_counter=$row['counter'];
如果($sub_counter!=0)
{
$count_string='('.$sub_counter.');
}
其他的
{
如果($cat_计数器!=0)
{
$count_string='('.$cat_counter.');
}
其他的
{
$count_string='';
}
}
如果($row['cat_color']!='')
{
$BG='bgcolor='。$row['cat_COLOR'];
}
其他的
{
$BG='';
}
//检索已翻译的类别名称
$row['cat_name']=$category_name[$row['cat_id'];
$catimage=(!empty($row['cat_image']))?“”:“”;
$TPL_main_值=“\t”。$catimage..”“\n”;
++美元周期;
如果($cycle==4)
{
$cycle=1;
$TPL\U主值=''。\n;
}
}
如果($cycle>=2&&$cycle
检查mysql($result、$query、\uuuuuu行、\uuuuu文件);
$need_to_continue=1;
$cycle=1;
$column=1;
$TPL_main_值=“”;
while($row=mysql\u fetch\u数组($result))
{
++$subcat_计数;
如果($cycle==1)
{
$TPL\U主值=''。\n;
}
$sub_counter=$row['sub_counter'];
$cat_counter=$row['counter'];
如果($sub_counter!=0)
{
$count_string='('.$sub_counter.');
}
其他的
{
如果($cat_计数器!=0)
{
$count_string='('.$cat_counter.');
}
其他的
{
$count_string='';
}
}
如果($row['cat_color']!='')
{
$BG='bgcolor='。$row['cat_COLOR'];
}
其他的
{
$BG='';
}
//检索已翻译的类别名称
$row['cat_name']=$category_name[$row['cat_id'];
$catimage=(!empty($row['cat_image']))?“”:“”;
$TPL_main_value.=“\t.”“”.$catimage.

”。“\n”; ++美元周期; 如果($cycle==4) { $cycle=1; $TPL\U主值=''。\n; ++$column; } }
如果($cycle>=2&&$cycle我也认为没有理由避免使用表,但也许这个简短的示例会让您更接近。公共表看起来像这样。让我们将所有标记更改为div,留下相应的类

<table>                            <div class="table">
    <tr>                               <div class="tr">
        <td>One</td>                       <div class="td">One</div>
        <td>Two</td>                       <div class="td">Two</div>
        <td>Three</td>                     <div class="td">Three</div>
    </tr>                  ==>         </div> 
    <tr>                               <div class="tr">
        <td>1</td>                         <div class="td">1</div>
        <td>2</td>                         <div class="td">2</div>
        <td>3</td>                         <div class="td">3</div>
    </tr>                              </div>
</table>                           </div>
就是这样。如果您添加多一点属性,它将看起来完全相同:
边框间距:2px;
用于表格div;
填充:1px;
用于单元格div

如果您希望您的示例如下所示:

+-------+-------+-------+
| .col1 | .col2 | .col3 |
+-------+-------+-------+
| .col4 | .col5 | .col6 |
+-------+-------+-------+
你必须用额外的div来包装每三个div

$TPL_main_value = '<div class="row">';
// instead of $TPL_main_value = '';
// then close it and open again every three loops
if ($i%3==0) $TPL_main_value = '</div><div class="row">';
// and don't forget to close it after while loop ends
$TPL\u main\u值=“”;
//而不是$TPL_main_value='';
//然后每三个循环关闭并再次打开
如果($i%3==0)$TPL\u main\u值=“”;
//循环结束后,不要忘记关闭它

也许会对你有所帮助

那么,为什么不使用表格呢?如果你在展示表格数据,表格通常是最符合逻辑的选择。@Mike Brant,因为我不想使用表格……不要相信表格是邪恶的思维方式。我同意5-10年前通常使用表格进行整个页面布局是不好的,但是使用表格来表示表格数据是不应该被反对的。事实上,这是最有经验的web开发人员做事情的首选方式。不使用表格(或下面vladkras的答案中指出的类似表格的结构)所面临的问题,是指您需要将基于行的数据库结果和concert转换为基于列的数据结构-需要将整个内容放在内存中。并不是说它们是邪恶的,它们不能与我正在使用的布局的其余部分一起工作。感谢您的可视化。不是我所想的。我添加了一些显示测试结果的详细信息。@mob你什么意思
他们
?他们指的是六列。我想改变php,所以我有三列,而不是六列要处理的额外DIV…@mobilestimulus检查我的答案,然后问我这个问题。php的哪一部分是说每个DIV只输入3s,然后再重新开始?如果我可以改变数学,那么问题就来了我想干什么就干什么,对吧?
<table>                            <div class="table">
    <tr>                               <div class="tr">
        <td>One</td>                       <div class="td">One</div>
        <td>Two</td>                       <div class="td">Two</div>
        <td>Three</td>                     <div class="td">Three</div>
    </tr>                  ==>         </div> 
    <tr>                               <div class="tr">
        <td>1</td>                         <div class="td">1</div>
        <td>2</td>                         <div class="td">2</div>
        <td>3</td>                         <div class="td">3</div>
    </tr>                              </div>
</table>                           </div>
.table { display: table; }
.tr { display: table-row; }
.td { display: table-cell; }
+-------+-------+-------+
| .col1 | .col2 | .col3 |
+-------+-------+-------+
| .col4 | .col5 | .col6 |
+-------+-------+-------+
$TPL_main_value = '<div class="row">';
// instead of $TPL_main_value = '';
// then close it and open again every three loops
if ($i%3==0) $TPL_main_value = '</div><div class="row">';
// and don't forget to close it after while loop ends