在php中以表格显示记录

时间:2014-05-12 15:53:26

标签: php mysql

大家好我想在PHP中显示我从MySQL数据库中获取的某些信息,问题是表格中没有显示任何内容,有人可以帮忙解决这个问题吗?

<?php
  require 'db2.php';
  $id = null;
  if ( !empty($_GET['id'])) {
    $id = $_REQUEST['id'];
  }
  if ( null==$id ) {
    header("Location: index.php");
  } else {
    $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not   connect to MySQL: ' . mysqli_connect_error() );
    $q = mysqli_query($dbc,"SELECT * FROM movie WHERE MovieID = '$id' ");
    while($r=mysqli_fetch_array($q))
    {   
      $title = $r["Title"];
      $tag = $r["Tag"];
      $Year = $r["YEAR"];
      $Cast = $r["Cast"];
    }
  }
?>

表格如下:

<div class="span10 offset1">
  <div class="row">
    <h3>Movie Information</h3>
  </div>

  <div class="form-horizontal" >
    <div class="control-group">
      <label class="control-label">Title</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['Title'];?>
        </label>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Year</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['email'];?>
        </label>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Cast</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['mobile'];?>
        </label>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label">Tags</label>
      <div class="controls">
        <label class="checkbox">
          <?php echo $r['mobile'];?>
        </label>
      </div>
      <div class="control-group">
        <label class="control-label">Image</label>
        <div class="controls">
        <label class="checkbox">
          <?php echo $r['mobile'];?>
        </label>
      </div>
    </div>
    <div class="form-actions">
      <a class="btn" href="index.php">Back</a>
      &nbsp; &nbsp;
      <a class="btn" href="index.php">Update</a>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:2)

您需要使用<?php echo $title;?>代替<?php echo $r['Title'];?>
因为您已经在$title = $r["Title"];

中分配了它

改变并为其他人做同样的事。