dsgnze6572
2015-08-08 04:27 阅读 78
已采纳

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

I need some help with php code. I want to put data that I get with this query into simple php/html table.

Can you guys help me with this?

<?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条回答 默认 最新

  • 已采纳
    dsa111111 dsa111111 2015-08-08 04:43
    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>
     ";
    }
    

    Something like this.. Hope it helps you.

    点赞 评论 复制链接分享
  • donglianglu8136 donglianglu8136 2015-08-08 04:47
    $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>";
         }
    
    点赞 评论 复制链接分享
  • dongluan5740 dongluan5740 2015-08-08 04:48

    Hello @filipche you can try by replacing your 'while' loop with following code:

    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>";
    

    Hope this is what you are looking for...

    点赞 评论 复制链接分享

相关推荐