如何在PHP中获取帖子的ID和标题?

时间:2010-09-07 15:05:37

标签: php

如何在PHP中获取帖子的ID和标题?每个帖子都有一个ID和一个标题,我需要能够同时获得这两个。

ID#      Title
1013     Name
1025     Name

1 个答案:

答案 0 :(得分:2)

你的问题有点不清楚。假设您使用MySQL,您可以获得这样的帖子的ID和标题:

<?php
$query = "SELECT id, title FROM table";
$result = mysql_query($query);

if(!$result)
{
    echo 'The query failed.<br />';
    echo mysql_error();
}
else
{
    //check if there are results
    if(mysql_num_rows($result) == 0)
    {
        echo 'No results.';
    }
    else
    {
        //loop through the results
        while($row = mysql_fetch_assoc($result))
        {
            echo 'ID: ' . $row['id'] . ', name: ' . $row['title'];
        }
    }
}
相关问题