显示数据库中的所有数据

时间:2015-03-30 14:02:49

标签: php mysql

我想显示数据库中的所有数据 我的数据库如下...... enter image description here

我在我的网站上实现了这一点...... enter image description here

但是我如何在每个表中加载这些数据。 我的代码如下......

<?php


include_once 'header.php';
$connection = mysql_connect("localhost", "root", "smogi")
?>

<html>
<head>

</head>
<body>
<?php
$result = queryMysql("SELECT * FROM doctor WHERE username='$username'");
if(mysql_num_rows($result))
{
?>
<!-- Koumpi pou se metaferei sti selida gia tin dimiourgia neas anakoinwseis -->
<form action="new_announcement.php">
    <input type="submit" value="Create New Announcement">
</form>
<?php
}
else
{
    $query  = "SELECT author,category,subject,content FROM announcements";
    $announcements= mysql_query($query,$connection);
    $counter = 0;
    $z=0;
    while($row = mysql_fetch_assoc($announcements)){
    $counter = $counter + 1;
?>

<table border="1" style="width:100%">
  <tr>
    <td><b>Author</b></td>
    <td><b>Category</b></td>        
    <td><b>Subject</b></td>
    <td><b>Content</b></td>
  </tr>
</table>
<?php
    }
}
?>
</body>
</html>

我搜索了stackoverflow,我找到了一些可以帮助我的解决方案。 我使用这个question from the stackoverflow来解决表的问题,但现在我如何将数据显示到每个表中

1 个答案:

答案 0 :(得分:1)

<?php


include_once 'header.php';
$connection = mysql_connect("localhost", "root", "smogi")
?>

<html>
<head>

</head>
<body>
<?php
$result = queryMysql("SELECT * FROM doctor WHERE username='$username'");
if(mysql_num_rows($result)):
?>
<!-- Koumpi pou se metaferei sti selida gia tin dimiourgia neas anakoinwseis -->
<form action="new_announcement.php">
    <input type="submit" value="Create New Announcement">
</form>
<?php else: ?>

<table border="1" style="width:100%">
  <tr>
    <td><b>Author</b></td>
    <td><b>Category</b></td>        
    <td><b>Subject</b></td>
    <td><b>Content</b></td>
  </tr>
<?php 
    $query  = "SELECT author,category,subject,content FROM announcements";
    $announcements= mysql_query($query,$connection);
    $counter = 0;
    $z=0;
    while($row = mysql_fetch_assoc($announcements)){
    $counter = $counter + 1;
?>
  <tr>
    <td><?php echo $row['author']?></td>
    <td><?php echo $row['category']?></td>        
    <td><?php echo $row['subject']?></td>
    <td><?php echo $row['content']?></td>
  </tr>
<?php
    }
endif;
?>
</table>
</body>
</html>
相关问题