如何将数组数据放入表中?

时间:2015-08-08 04:27:52

标签: php mysql html5

我需要一些PHP代码的帮助。 我想把这个查询得到的数据放到简单的php / html表中。

你们能帮助我吗?

<?php

$konekcija=mysqli_connect("111.111.111.111","test","test123","publishers_instagram_accounts");
if (mysqli_connect_errno())
    die ("Error:".mysqli_connect_error());

$select = "select * from publishers_instagram_accounts where followed_id <= (select followed_id from publishers_instagram_accounts where username='zika')*1.2 and followed_id >= (select followed_id from publishers_instagram_accounts where username='zika')*0.8";

$stmt = mysqli_prepare($konekcija, $select);

if (mysqli_error($konekcija))
    die ("Error:" . mysqli_error($konekcija));

mysqli_stmt_bind_param($stmt, "ss", $trazi1, $trazi2);

if (!mysqli_stmt_execute($stmt))
{
    die ("Error:" . mysqli_stmt_error($stmt));
}
else
{
    $rezultat = mysqli_stmt_get_result($stmt);

    while ($red = mysqli_fetch_array($rezultat, MYSQL_ASSOC))
    {
        var_dump($red);
    }
}

3 个答案:

答案 0 :(得分:2)

while ($red = mysqli_fetch_array($rezultat, MYSQL_ASSOC)) {
 echo "
 <table>
  <thead>
    <td>Username</td>
    <td>Password</td>
  </thead>
  <tbody>
    <td>$red['username']</td>
    <td>$red['password']</td>
  </tbody>
</table>
 ";
}

这样的东西..希望它能帮到你。

答案 1 :(得分:0)

您好@filipche您可以尝试使用以下代码替换'while'循环:

echo "<table><thead><tr><th>Field 1</th><th>Field 2</th><th>Field 3</th></tr></thead>";
while ($red = mysqli_fetch_array($rezultat, MYSQL_ASSOC)) {
   echo "<tbody><tr>";
   echo "<td>".$red["field1"]."</td>";
   echo "<td>".$red["field2"]."</td>";
   echo "<td>".$red["field3"]."</td>";
   echo "</tr><tbody>";
}
echo "</table>";

希望这就是你要找的......

答案 2 :(得分:-1)

$qstring = "Your query goes here";
$result = mysql_query($qstring);
if($result)
{
     while($row = mysql_fetch_array($result))
     {
          echo "<table>";
          echo "<td>".$row[column name]."</td>";echo "</table>";
     }