围绕文本在PHP中创建边框

时间:2014-12-11 09:27:26

标签: php html css

我正在尝试制作一个可打印的表单,其中信息是使用php从mysql数据库中提取的,我想在表单中的某些文本周围做一个寄存器,但我已经尝试使用

<div "style="border: 5px solid #aaa;"> </div>但它出现了语法错误Unexpected "<"

我尝试使用

p.two {
    border-style: solid;
    border-width: medium;
}

然后把它放在echo的开头

<p class="two">

但这也不起作用。这是我目前的完整代码;

<!DOCTYPE html>
<html>
<head>
<style>

p.one {
    border-style: solid;
    border-width: 5px;
}

p.two {
    border-style: solid;
    border-width: medium;
}

</style>

<body>

<p class="two">
    <strong><u><center><font size="10">Asset Form</font size="10"></center></u></strong>
</p>


<?php


$servername = "localhost";
$username = "appuser1";
$password = "******";
$dbname = "acmefg_app";


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, jobnumber, assetnumber, serialnumber, make, model, description, refrigeranttype, refrigerantqty, itemcondition, installdate, location, comments, maintcomp FROM appdata";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     // output data of each row


     $row = $result->fetch_assoc();
         echo "<br> ID: ". $row["id"].  "<br>";
         echo "<br> Job number: ". $row["jobnumber"]. "<br>";
         echo "<br> Asset number: " . $row["assetnumber"] . "<br>";
         echo "<br> Serial Number: " . $row["serialnumber"] . "<br>";
         echo "<br> Make: " . $row["make"] . "<br>";
         echo "<br> Model: " . $row["model"] . "<br>";
         echo "<br> Description: " . $row["description"] . "<br>";
         echo "<br> refrigeranttype: " . $row["refrigeranttype"] . "<br>";
         echo "<br> refrigerantqty: " . $row["refrigerantqty"] . "<br>";
         echo "<br> itemcondition: " . $row["itemcondition"] . "<br>";
         echo "<br> installdate: " . $row["installdate"] . "<br>";
         echo "<br> location: " . $row["location"] . "<br>";
         echo "<br> comments: " . $row["comments"] . "<br>";
         echo "<br> maintcomp: " . $row["maintcomp"] . "<br>";
     }


$conn->close();
?> 





</body>
</html>

我想要本节中的所有内容;

 $row = $result->fetch_assoc();
         echo "<br> ID: ". $row["id"].  "<br>";
         echo "<br> Job number: ". $row["jobnumber"]. "<br>";
         echo "<br> Asset number: " . $row["assetnumber"] . "<br>";
         echo "<br> Serial Number: " . $row["serialnumber"] . "<br>";
         echo "<br> Make: " . $row["make"] . "<br>";
         echo "<br> Model: " . $row["model"] . "<br>";
         echo "<br> Description: " . $row["description"] . "<br>";
         echo "<br> refrigeranttype: " . $row["refrigeranttype"] . "<br>";
         echo "<br> refrigerantqty: " . $row["refrigerantqty"] . "<br>";
         echo "<br> itemcondition: " . $row["itemcondition"] . "<br>";
         echo "<br> installdate: " . $row["installdate"] . "<br>";
         echo "<br> location: " . $row["location"] . "<br>";
         echo "<br> comments: " . $row["comments"] . "<br>";
         echo "<br> maintcomp: " . $row["maintcomp"] . "<br>";
     }

包含在边框中。 有人可以帮我解决一下这个问题吗?

3 个答案:

答案 0 :(得分:3)

您需要删除div中的第一个"

<div "style="border: 5px solid #aaa;">

应改为

<div style="border: 5px solid #aaa;">


您可以将它放在代码中的任何位置。在您的示例中,您可以像这样使用它:

echo '<div style="border: 5px solid #aaa;">';
$row = $result->fetch_assoc();
         echo "<br> ID: ". $row["id"].  "<br>";
         echo "<br> Job number: ". $row["jobnumber"]. "<br>";
         echo "<br> Asset number: " . $row["assetnumber"] . "<br>";
         echo "<br> Serial Number: " . $row["serialnumber"] . "<br>";
         echo "<br> Make: " . $row["make"] . "<br>";
         echo "<br> Model: " . $row["model"] . "<br>";
         echo "<br> Description: " . $row["description"] . "<br>";
         echo "<br> refrigeranttype: " . $row["refrigeranttype"] . "<br>";
         echo "<br> refrigerantqty: " . $row["refrigerantqty"] . "<br>";
         echo "<br> itemcondition: " . $row["itemcondition"] . "<br>";
         echo "<br> installdate: " . $row["installdate"] . "<br>";
         echo "<br> location: " . $row["location"] . "<br>";
         echo "<br> comments: " . $row["comments"] . "<br>";
         echo "<br> maintcomp: " . $row["maintcomp"] . "<br>";
     }

echo '</div>';

请查看此LINK以获取有关如何将边框样式添加到不同div的示例。

this link关于如何使用类来应用样式。

答案 1 :(得分:1)

正确的内联css就像这样

<div style="border: 5px solid #aaa;"> </div>

删除 - &gt;中的双引号"style=

http://border-radius.com/

答案 2 :(得分:1)

更改:

<div "style="border: 5px solid #aaa;"> </div>

<div style="border: 5px solid #555;"> </div>

使用它:

echo '<div style="border: 5px solid #555;">';
$row = $result->fetch_assoc();
         echo "<br> ID: ". $row["id"].  "<br>";
         echo "<br> Job number: ". $row["jobnumber"]. "<br>";
         echo "<br> Asset number: " . $row["assetnumber"] . "<br>";
         echo "<br> Serial Number: " . $row["serialnumber"] . "<br>";
         echo "<br> Make: " . $row["make"] . "<br>";
         echo "<br> Model: " . $row["model"] . "<br>";
         echo "<br> Description: " . $row["description"] . "<br>";
         echo "<br> refrigeranttype: " . $row["refrigeranttype"] . "<br>";
         echo "<br> refrigerantqty: " . $row["refrigerantqty"] . "<br>";
         echo "<br> itemcondition: " . $row["itemcondition"] . "<br>";
         echo "<br> installdate: " . $row["installdate"] . "<br>";
         echo "<br> location: " . $row["location"] . "<br>";
         echo "<br> comments: " . $row["comments"] . "<br>";
         echo "<br> maintcomp: " . $row["maintcomp"] . "<br>";
     }
echo '</div>';

但是为div使用一个类可能更好。然后,您可以修改样式表中的所有样式。

例如:

&#13;
&#13;
.product {
  font-size: 16px;
  font-family: Helvetica;
}

.product ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.product ul li {
  /* Nort West South East */
  padding: 5px 0px 5px 0px;
  font-size: 20px;
  font-family: Arial;
}
&#13;
<div class="product">
  <br> ID: 1<br>
  <br> Job number: 1234<br>
  <br> Asset number: 3546<br>
  <br> Serial Number: 45673453456<br>
  <br> Make: Bosch<br>
  <br> Model: 4765678<br>
  <br> Description: Example<br>
  <br> refrigeranttype: 4653456<br>
  <br> refrigerantqty: 3<br>
  <br> itemcondition: new<br>
  <br> installdate: 3-4-2014<br>
  <br> location: NY<br>
  <br> comments: none<br>
  <br> maintcomp: 5463456<br>
</div>

<!-- Or maybe even better -->

<div class="product">
  <ul>
    <li> ID: 1</li>
    <li> Job number: 1234</li>
    <li> Asset number: 3546</li>
    <li> Serial Number: 45673453456</li>
    <li> Make: Bosch</li>
    <li> Model: 4765678</li>
    <li> Description: Example</li>
    <li> refrigeranttype: 4653456</li>
    <li> refrigerantqty: 3</li>
    <li> itemcondition: new</li>
    <li> installdate: 3-4-2014</li>
    <li> location: NY</li>
    <li> comments: none</li>
    <li> maintcomp: 5463456</li>
  </ul>
</div>
&#13;
&#13;
&#13;