在每组记录之后使用<hr />

时间:2015-11-17 12:17:30

标签: php

我有一个搜索结果表单,我有一个问题,我不知道如何使用&lt; .hr /&gt;行在每组记录之后。 当你看到下一个用户的结果接近前一个用户时。

  

这是我的代码:

.
.
.
<?php

$firstname = '';
$oldfirst = '';

$lastname = '';
$oldlast = '';

$phone_number = '';
$oldphone_number = '';

$positive = '';
$oldpositive = '';

$negative = '';
$oldnegative = '';

while ($row = mysql_fetch_array($dbresult, MYSQL_ASSOC)) {

    if($oldfirst == $row['name'] &&
       $oldlast == $row['family'] &&
       $oldphone_number == $row['phone_number'] &&
       $oldpositive == $row['positive'] &&
       $oldnegative == $row['negative'])
    {
        $firstname = ' ';
        $lastname = ' ';
        $phone_number = ' ';
        $positive = ' ';
        $negative = ' ';
        /***************/
        $namelabel = ' ';
        $phone_numberlabel= ' ';
        $positivelabel = ' ';
        $negativelabel = ' ';
    }
    else
    {
        $firstname = $row['name'];
        $lastname = $row['family'];
        $phone_number = $row['phone_number'];
        $positive = $row['positive'];
        $negative = $row['negative'];
        /*********************/
        $namelabel = 'نام: ';
        $phone_numberlabel= 'شماره تلفن: ';
        $positivelabel = 'عملیات های موفق: ';
        $negativelabel = 'عملیات نا موفق: ';
    }

    $oldfirst = $row['name'];
    $oldlast = $row['family'];
    $oldphone_number = $row['phone_number'];
    $oldpositive = $row['positive'];
    $oldnegative = $row['negative'];


printf("{$namelabel} %s   %s &nbsp&nbsp&nbsp
        {$phone_numberlabel} %s &nbsp&nbsp&nbsp

        {$positivelabel} %s &nbsp&nbsp&nbsp
        {$negativelabel} %s &nbsp&nbsp&nbsp <br/>
        شغل: %s &nbsp&nbsp&nbsp
        توضیحات: %s",
        $firstname,
        $lastname,
        $phone_number,
        $positive,
        $negative,
        $row["job_name"], 
        $row["comments"]);
    }
?>

放置&lt; .hr /&gt;的位置划分结果?

  

这是代码的结果:

enter image description here

  有些人做了这个,它不是真的,不适用于每组信息。另外做一个空行:

enter image description here

3 个答案:

答案 0 :(得分:4)

首先注意,这条线是水平的,你不能破坏它。然后,它可以放在双引号之间的任何地方&#34;&#34;。哦,它没有点 - &gt; <hr/>

printf("{$namelabel} %s   %s &nbsp&nbsp&nbsp
        {$phone_numberlabel} %s &nbsp&nbsp&nbsp

        {$positivelabel} %s &nbsp&nbsp&nbsp
        {$negativelabel} %s &nbsp&nbsp&nbsp <br/>
        شغل: %s &nbsp&nbsp&nbsp
        توضیحات: %s <hr/>",
        $firstname,
        $lastname,
        $phone_number,
        $positive,
        $negative,
        $row["job_name"], 
        $row["comments"]);
    }

编辑:

if($oldfirst == $row['name'] &&
   $oldlast == $row['family'] &&
   $oldphone_number == $row['phone_number'] &&
   $oldpositive == $row['positive'] &&
   $oldnegative == $row['negative'])
{
    $firstname = ' ';
    $lastname = ' ';
    $phone_number = ' ';
    $positive = ' ';
    $negative = ' ';
    /***************/
    $hr = '';
    $namelabel = ' ';
    $phone_numberlabel= ' ';
    $positivelabel = ' ';
    $negativelabel = ' ';
}
else
{
    $firstname = $row['name'];
    $lastname = $row['family'];
    $phone_number = $row['phone_number'];
    $positive = $row['positive'];
    $negative = $row['negative'];
    /*********************/
    $hr = '<hr/>';
    $namelabel = 'نام: ';
    $phone_numberlabel= 'شماره تلفن: ';
    $positivelabel = 'عملیات های موفق: ';
    $negativelabel = 'عملیات نا موفق: ';
}

然后

echo $hr;
printf("{$namelabel} %s   %s &nbsp&nbsp&nbsp
        {$phone_numberlabel} %s &nbsp&nbsp&nbsp

        {$positivelabel} %s &nbsp&nbsp&nbsp
        {$negativelabel} %s &nbsp&nbsp&nbsp <br/>
        شغل: %s &nbsp&nbsp&nbsp
        توضیحات: %s",
        $firstname,
        $lastname,
        $phone_number,
        $positive,
        $negative,
        $row["job_name"], 
        $row["comments"]);
    }

答案 1 :(得分:0)

试试这个。它会解决你的问题。

<?php

$firstname = '';
$oldfirst = '';

$lastname = '';
$oldlast = '';

$phone_number = '';
$oldphone_number = '';

$positive = '';
$oldpositive = '';

$negative = '';
$oldnegative = '';

while ($row = mysql_fetch_array($dbresult, MYSQL_ASSOC)) {

    if($oldfirst == $row['name'] &&
       $oldlast == $row['family'] &&
       $oldphone_number == $row['phone_number'] &&
       $oldpositive == $row['positive'] &&
       $oldnegative == $row['negative'])
    {
        $firstname = ' ';
        $lastname = ' ';
        $phone_number = ' ';
        $positive = ' ';
        $negative = ' ';
        /***************/
        $namelabel = ' ';
        $phone_numberlabel= ' ';
        $positivelabel = ' ';
        $negativelabel = ' ';
        $hr=""; // add $hr variable and set value null for repeating records
    }
    else
    {
        $firstname = $row['name'];
        $lastname = $row['family'];
        $phone_number = $row['phone_number'];
        $positive = $row['positive'];
        $negative = $row['negative'];
        /*********************/
        $namelabel = 'نام: ';
        $phone_numberlabel= 'شماره تلفن: ';
        $positivelabel = 'عملیات های موفق: ';
        $negativelabel = 'عملیات نا موفق: ';
        $hr="<hr/>"; // add $hr variable and set value <hr/> for unique records
    }

    $oldfirst = $row['name'];
    $oldlast = $row['family'];
    $oldphone_number = $row['phone_number'];
    $oldpositive = $row['positive'];
    $oldnegative = $row['negative'];


printf("{$namelabel} %s   %s &nbsp&nbsp&nbsp
        {$phone_numberlabel} %s &nbsp&nbsp&nbsp

        {$positivelabel} %s &nbsp&nbsp&nbsp
        {$negativelabel} %s &nbsp&nbsp&nbsp <br/>
        شغل: %s &nbsp&nbsp&nbsp
        توضیحات: %s",
        $firstname,
        $lastname,
        $phone_number,
        $positive,
        $negative,
        $row["job_name"], 
        $row["comments"]);
        echo $hr; // echo <hr/> here
    }
?>

答案 2 :(得分:0)

printf之后

如下。

printf("{$namelabel} %s %s &nbsp&nbsp&nbsp {$phone_numberlabel} %s &nbsp&nbsp&nbsp {$positivelabel} %s &nbsp&nbsp&nbsp {$negativelabel} %s &nbsp&nbsp&nbsp <br/> شغل: %s &nbsp&nbsp&nbsp توضیحات: %s", $firstname, $lastname, $phone_number, $positive, $negative, $row["job_name"], $row["comments"]); 
echo '<hr/>';