PHP表只在第一行SQL查询中生成样式 [英] PHP table only generating style on first row of SQL query

查看:64
本文介绍了PHP表只在第一行SQL查询中生成样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试创建自己的PHP论坛。



我已设法从我的数据库中检索并显示3行中的3行,但只对第一个记录进行了适当的样式设置。下面是我到目前为止的PHP代码:



Hi there,

I'm trying to create my own PHP forum.

I have managed to retrieve and display 3 of 3 rows from my database but only the first record is being styled appropriately. Below is the PHP code I have so far:

<?php
$sql = "SELECT cat_id, cat_name, cat_description FROM categories";
 
$result = mysql_query($sql);
 
if(!$result)
{
    echo 'The categories could not be displayed, please try again later.';
}
else
{
    if(mysql_num_rows($result) == 0)
    {
        echo 'No categories defined yet.';
    }
    else
    {
		?>
        <table>
        	<tr>
            	<th>Category</th>
                <th>Last topic</th>
         	</tr>
        <?php     
        while($row = mysql_fetch_assoc($result))
        {               
			echo '<tr>';
                echo '<td class="leftpart">';
                    echo '<h3><a href="category.php?cat_id">' . $row['cat_name'] . '</a></h3>' . $row['cat_description'];
                echo '</td>';
                echo '<td class="rightpart">';
                            echo '<a href="topic.php?topic_id">Topic subject</a> at 10-10';
                echo '</td>';
            echo '</tr>';
		   echo '</table>';
        }
    }
}
?>
<?php 





有什么我想念的吗?



Is there something i'm missing?

推荐答案

sql = SELECT cat_id,cat_name,cat_description FROM categories ;

sql = "SELECT cat_id, cat_name, cat_description FROM categories";


result = mysql_query(
result = mysql_query(


sql) ;

if(!
sql); if(!


这篇关于PHP表只在第一行SQL查询中生成样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆