如何在PHP中获得帖子的ID和标题?
问题描述:
如何在PHP中获取帖子的ID和标题?每篇文章都有一个ID和一个标题,我需要能够同时获得这两个。如何在PHP中获得帖子的ID和标题?
ID# Title
1013 Name
1025 Name
答
你的问题有点不清楚。假设你使用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'];
}
}
}
+0
+1:努力。 – shamittomar 2010-09-07 15:27:16
+0
谢谢 - 这有效!欣赏时间。我的PHP非常薄弱。 - 迈克 – 2010-09-23 03:24:37
你正在使用数据库来存储数据或文件吗?如果你使用的是MySQL,那里有大量的教程可用于'用PHP获取数据mysql',这将有助于你完成这项任务。以下是我找到的第一个结果的链接:http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/retrieve-data-from-a-mysql-database.aspx – 2010-09-07 15:10:05