Php 如何从sql表创建div/tile
抱歉,如果这听起来很无聊,没有太多的web开发经验,并且试图为我的项目找到最好的解决方案 我有一个sql表,从中我可以在php文件中回显如下数据:Php 如何从sql表创建div/tile,php,html,css,sql,jquery-isotope,Php,Html,Css,Sql,Jquery Isotope,抱歉,如果这听起来很无聊,没有太多的web开发经验,并且试图为我的项目找到最好的解决方案 我有一个sql表,从中我可以在php文件中回显如下数据: echo "<table border='1'> <tr> <th>username</th> <th>objectname</th> <th>url</th> <th>description</th> <th>pict
echo "<table border='1'>
<tr>
<th>username</th>
<th>objectname</th>
<th>url</th>
<th>description</th>
<th>picture</th>
<th>price</th>
<th>location</th>
<th>category</th>
<th>priority</th>
<th>event</th>
<th>tags</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['objectname'] . "</td>";
echo "<td>" . $row['url'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['picture'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['priority'] . "</td>";
echo "<td>" . $row['event'] . "</td>";
echo "<td>" . $row['tags'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo”
用户名
对象名
网址
描述
照片
价格
位置
类别
优先
事件
标签
";
while($row=mysqli\u fetch\u数组($result))
{
回声“;
回显“$row['username']”;
回显“$row['objectname']”;
回显“$row['url']”;
回显“$row['description']”;
回显“$row['picture']”;
回显“$row['price']”;
回显“$row['location']”;
回显“$row['category']”;
回显“$row['priority']”;
回显“$row['event']”;
回显“$row['tags']”;
回声“;
}
回声“;
这将为该用户提取整个SQL表。我想在一个单独的div中分别回显每一行的内容,这样我就可以使用同位素jquery插件中的平铺来可视化/回显它
根据行数动态生成多个div并用每行数据填充它们的最佳方法是什么
再一次,如果这太宽了,我很抱歉
谢谢 如果您的sql表id具有自动递增功能,那么您可以将其用于div分隔,也可以使用如下方法
$i = 1;
while($row = mysqli_fetch_array($result))
{
echo "<div id='".$i."'>";
echo "username:" . $row['username'] . "<br />";
echo "objectname:" . $row['objectname'] . "<br />";
echo "url:" . $row['url'] . "<br />";
echo "description:" . $row['description'] . "<br />";
echo "picture:" . $row['picture'] . "<br />";
echo "price:" . $row['price'] . "<br />";
echo "</div>";
$i++;
}
$i=1;
while($row=mysqli\u fetch\u数组($result))
{
回声“;
回显“用户名:.”行['username']。“
”;
echo“objectname:”.$row['objectname'].“
”;
回显“url:.$行['url']。”
;
echo“description:”.$row['description']。“
”;
echo“picture:.$row['picture'].“
”;
echo“价格:.”行['price']。“
”;
回声“;
$i++;
}
如果需要不同div中的行,只需
while($row = mysqli_fetch_array($result))
{
echo "<div>";
echo "<div>" . $row['username'] . "</div>";
// SOME OTHER RECORDS
echo "</div>";
}
while($row=mysqli\u fetch\u数组($result))
{
回声“;
回显“$row['username']”;
//其他一些记录
回声“;
}
此外,还可以向div添加ID
while($row = mysqli_fetch_array($result))
{
echo '<div id="sample_'.$row[id].'">';
echo "<div>" . $row['username'] . "</div>";
// SOME OTHER RECORDS
echo "</div>";
}
while($row=mysqli\u fetch\u数组($result))
{
回声';
回显“$row['username']”;
//其他一些记录
回声“;
}
您需要一个div中的所有字段或单独div中的所有列吗?请使用英文文本,没有它们,您的文本看起来不太好。