从同一页面上的DB获取数据

时间:2014-02-03 20:02:44

标签: php database mysqli

我试图让用户输入一个帐号,并在商家名称下面显示。

以下是我正在使用的代码,该代码从表单中调用:

 <?php
    $q = intval($_GET['q']);

    $con = mysql_connect("localhost","cl49-xxx","xxx");
    if (!$con)
      {
      die('Could not connect: ' . mysqli_error($con));
      }

    mysqli_select_db($con,"cl49-xx");
    $sql="SELECT * FROM member WHERE personID = '".$q."'";

    $result = mysqli_query($con,$sql);


    echo "Business Name:<table>";

    while($row = mysqli_fetch_array($result)) 
      {
      echo "<tr>";
      echo "<td>" . $row['businesstype'] . "</td>";

      echo "</tr>";
      }
    echo "</table>";

    mysqli_close($con);
 ?>

当我运行此代码时,它只显示business name:

1 个答案:

答案 0 :(得分:0)

我认为你在循环附近有问题。而不是“while($ row = mysqli_fetch_array($ result))”。你为什么不用这个:

$row = mysqli_fetch_array($result);
$i= 0;
    while( $i<count($row)) 
          {

          echo "<tr>";
          echo "<td>" . $row['businesstype'] . "</td>";

          echo "</tr>";
           $i++;
          }
        echo "</table>";