组织表中数据的显示 [英] organize display of data from table

查看:55
本文介绍了组织表中数据的显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表rsales和salessumarry,并且我有这个ff值.

i have two tables rsales and salessumarry and i have this ff value.

salessumarry的价值

value from salessumarry

date       |  receipt  |
09/29/2103 |  112233   |

销售价格

name       |  category  | receipt  |
33uf       |  capacitor |  112233  |
ic         |  ic22      |  112233  |

期望的输出一定是这样的.

THE EXPECTED OUTPUT MUST BE SOMETHING LIKE THIS.

    date       |  receipt  |
    09/29/2103 |  112233   |
   *name       | category  | receipt  |*
    33uf       | capacitor |  112233  |
    ic         | ic22      |  112233  |

但是我得到这样的结果,这是错误的.到目前为止,我的代码如下.

but i get a result like this which is wrong. i have my code below so far.

    date       |  receipt  |
    09/29/2103 |  112233   |
   *name       | category  | receipt  |*
    33uf       | capacitor |  112233  |
   *name       | category  | receipt  |*
    ic         | ic22      |  112233  |

到目前为止,我有这个ff代码

and i have this ff code so far

$a=$_POST['dayfrom'];
$b=$_POST['dayto'];

    $result1 = mysql_query ("SELECT s.*, r.category, r.name,r.receipt
    FROM salessumarry s
    JOIN rsales r ON s.reciept = r.reciept
    WHERE s.register_mode = 'sales'
    AND s.date BETWEEN '$a' AND '$b' ");

    while($row = mysql_fetch_array($result1))
    {
        echo '<tr>';
        echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['date'].'</div></td>';
        echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['reciept'].'</div></td>';
        echo '</div></td>';
        echo '</tr>';

        echo '<th style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['name'].'</div>
        echo '<th style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['category'].'</div></th>';
        echo '<th style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['receipt'].'</div></th>';                              


        echo '<tr>';                        
        echo '<th style="border-color:#000000; border-style:solid; border-width:1px;font-size:10px;background-image:url(images/buts3.png);color:white"">name</th>';
        echo '<th style="border-color:#000000; border-style:solid; border-width:1px;font-size:10px;background-image:url(images/buts3.png);color:white"">category</th>';

        echo '<th style="border-color:#000000; border-style:solid; border-width:1px;font-size:10px;background-image:url(images/buts3.png);color:white"">receipt</th>';
 }
mysql_close($con);
?>  

推荐答案

对不起,如果我误解了这个问题-您发布的代码似乎无法产生您发布的输出,不过,这是我的两分钱;我认为,要解决表格标题在整个结果中重复出现的问题,您需要放置以下内容:

I'm sorry If I have misunderstood the question- the code you posted does not seem to produce the output you posted, nevertheless, here's my two cents; I think that to fix the problem you are having with the table headers repeating throughout the results, you need to place the block which reads:

 echo '<tr>';                        
    echo '<th style="border-color:#000000; border-style:solid; border-width:1px;font-size:10px;background-image:url(images/buts3.png);color:white"">Product Code</th>';
    echo '<th style="border-color:#000000; border-style:solid; border-width:1px;font-size:10px;background-image:url(images/buts3.png);color:white"">Name</th>';

在if块中,它仅显示一次:

In side an if block, such that it only displays once:

if(!$displayed) {
    $displayed = true;
    echo '<tr>';                        
    echo '<th style="border-color:#000000; border-style:solid; border-width:1px;font-size:10px;background-image:url(images/buts3.png);color:white"">Product Code</th>';
    echo '<th style="border-color:#000000; border-style:solid; border-width:1px;font-size:10px;background-image:url(images/buts3.png);color:white"">Name</th>';
}

并且不要忘记在 while循环之前将$ displayed初始化为false.

And do not forget to initialize $displayed to false before the while loop.

此外,但除了实际问题外,您发布的此代码非常不安全,因为它容易受到称为sql注入的攻击的攻击.我建议您使用类似PDO准备的语句来确保您不会遭受安全性问题.

In addition, but somewhat aside from the actual question this code you have posted is very insecure, as it is vulnerable to an attack known as sql injection. I recommend you use something like PDO prepared statements to make sure that you do not suffer security problems.

这篇关于组织表中数据的显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆