我连接数据库,根据关键字段搜索数据库内容,然后在网页中显示。
满足条件的信息有些在两条以上,不过它们每行显示的内容都一模一样,怎么让它显示不同行就不同的数据??
代码如下:<?php
header("Content-Type: text/html; charset=ISO-8859-1");
include("db_conn.php");if($_POST[buyeremail]==" ")
{
echo "<script>";
echo "alert('Please enter a query of the user's mailbox');";
echo "location.href=\"check.php\";";
echo "</script>";
}
else
{
$sql="select * from A where Email='$_POST[buyeremail]'";
$res=mysql_query($sql); if(mysql_num_rows($res)>0)
{
$num = mysql_num_rows($res);
$row=mysql_fetch_array($res);
?>
<table width="900" border="1" cellpadding="0" cellspacing="0" align="center">
 <tr>
  <td width="5%" align="center">RecordNumner</td>
  <td width="5%" align="center">UserId</td>
  <td width="20%" align="center">Fullname</td>
  <td width="20%" align="center">Email</td>
  <td width="20%" align="center">Address</td>
  <td width="30%" align="center">ItemTitle</td>
 </tr>
 <tr><td colspan='10'><hr width='100%'></td></tr>
<?php
  for ($i=1;$i<=$num;$i++)
  {
  echo "<tr><td width='5%' align='center'>".$row['RecordNumber']."</td>";
  echo "<td width='5%' align='center'>".$row['UserId']."</td>";
  echo "<td width='20%' align='center'>".$row['Fullname']."</td>";
  echo "<td width='20%' align='center'>".$row['Email']."</td>";
  echo "<td width='20%' align='center'>".$row['BuyerAddress']."<br>".$row['BuyerTownOrCity']."<br>".$row['BuyerCounty']."&nbsp;".$row['BuyerPostcode']."<br>".$row['BuyerCountry']."</td>";
  echo "<td width='30%' align='center'>".$row['ItemTitle']."</td>";
  }
?>
</table>
<?php
}
else
{
echo "<div align='center'>Sorry, there is no such person information</div>";
}
}
?>
A表的字段有:RecordNumber,UserId,Fullname,Email,BuyerAddress,ItemTitle数据库中满足这个条件的记录有三条,其中前面五个字段的信息都一样的,就是最后的那个ItemTitle是不一样的

解决方案 »

  1.   

    ...
        if(mysql_num_rows($res)>0)
        {
            $num = mysql_num_rows($res);
            //$row=mysql_fetch_array($res);
    ?>
    <table width="900" border="1" cellpadding="0" cellspacing="0" align="center">
     <tr>
      <td width="5%" align="center">RecordNumner</td>
      <td width="5%" align="center">UserId</td>
      <td width="20%" align="center">Fullname</td>
      <td width="20%" align="center">Email</td>
      <td width="20%" align="center">Address</td>
      <td width="30%" align="center">ItemTitle</td>
     </tr>
     <tr><td colspan='10'><hr width='100%'></td></tr>
    <?php
      while($row=mysql_fetch_array($res))
      {
          echo "<tr><td width='5%' align='center'>".$row['RecordNumber']."</td>";
          echo "<td width='5%' align='center'>".$row['UserId']."</td>";
          echo "<td width='20%' align='center'>".$row['Fullname']."</td>";
          echo "<td width='20%' align='center'>".$row['Email']."</td>";
          echo "<td width='20%' align='center'>".$row['BuyerAddress']."<br>".$row['BuyerTownOrCity']."<br>".$row['BuyerCounty']."&nbsp;".$row['BuyerPostcode']."<br>".$row['BuyerCountry']."</td>";
          echo "<td width='30%' align='center'>".$row['ItemTitle']."</td>";
      }
    ?>
    </table>
    ...
      

  2.   

    这句要放循环里
    $row=mysql_fetch_array($res);