我目前正在处理一个包含“名称”、“信息”、“价格”和“持续时间”的表。但是 PHP 脚本已连接到数据库。
我想使用 PHP 和 SQL 通过数据库自动填充表格单元格:“名称”、“价格”、“持续时间”,这对我来说非常适合。不过,我想自定义各个信息单元格中的内容(例如,阅读更多 jQuery 并重定向到其他页面)。
我尝试了一些在数据库内使用标签和其他奇怪的东西,但显然不起作用。
有没有一种更优雅的方法来解决我的问题,而不是在没有 PHP/SQL 的情况下设置一个完整的普通表,我必须手动输入有关名称、价格和持续时间的每一位数据?
<table class="table table-bordered table-hover tablesorter row sortable">
<thead>
<tr>
<th class="header">Name</th>
<th class="hidden-xs">Info</th>
<th>Price (in Euro)</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
<?php
//Connect to Database
$db=mysql_connect ("xxxx", "xxxx", "xxxx") or die ('Oops! Da hat wohl' . mysqli_error(). 'Mist gebaut');
//Choose Database
$mydb=mysql_select_db("massageke_de");
//Query Database
$sql="SELECT * FROM Angebote";
//-run the query against the mysql query function
$result=mysql_query($sql);
//Show Results
while($row=mysql_fetch_array($result)){
//Start table ?>
<tr>
<td class="col-sm-2"><?php echo $Name =$row['Name'] ; ?></td>
<!--In this <td>-tag I want to put long textes with links-->
<td class="hidden-xs col-sm-5">echo $Name =$row['Info'];?<</td>
<td class="col-sm-2"><?php echo $Preis =$row['Preis']; ?></td>
<td ckass="col-sm-1"><?php echo $Dauer =$row['Dauer']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
预先感谢您的帮助。 不要费心问我其他问题。
P.S.:我希望你能提供帮助,而不需要我使用的 Bootstrap CSS。
P.P.S.:我知道我的 PHP 脚本不受 PHP 注入(inject)保护 (但我想要并且将会学习如何保护它)
编辑:正如杰斯特所要求的那样。我用 Photoshop 很快就完成了它,因为我认为图像可以比我糟糕的编码技能更好地表达我想要实现的目标。 Get to the image
最佳答案
在我看来,最简单的方法就是编辑每个数据库中的信息列?如果你想在 php 中执行此操作,我建议使用名称(ids 会更好,但似乎你无权访问这些?)作为键创建一个数组:
$info['Aroma Teilkoerper'] = "Text about aroma teilkoerper";
$info['Aroma Ganzkoerper'] = "Text about aroma ganzkoerper";
依此类推,直到拥有所有内容。然后在循环中:
//Show Results
while($row=mysql_fetch_array($result)){
//Start table ?>
<tr>
<td class="col-sm-2"><?php echo $Name =$row['Name'] ; ?></td>
<!--In this <td>-tag I want to put long textes with links-->
<td class="hidden-xs col-sm-5">echo $Name =$info[$row['Name']];?></td>
<td class="col-sm-2"><?php echo $Preis =$row['Preis']; ?></td>
<td ckass="col-sm-1"><?php echo $Dauer =$row['Dauer']; ?></td>
</tr>
<?php } ?>
希望这对您来说是一个可行的解决方案? (您的 php 结束标记中也存在语法错误。
echo $Name =$row['Info'];?< // <----- should be ?> of course
关于php - 在自动填充的 PHP 表之间放置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36408625/