|
发表于 2005-8-24 21:32:38
|
显示全部楼层
兔兔给段代码,希望对你有所帮助
[code:1]
<?php
define("_TABLE_POSTS", "phpbb_posts");
define("_TABLE_USERS", "phpbb_users");
/* 满足您的MySQL的配置 */
$db = new mysqli("localhost", "root", "123456", "phpbb2");
/* 检测连接 */
if (mysqli_connect_errno()) {
printf("Connect failed: %s", mysqli_connect_error());
exit();
} else {
echo "connect succeed.<br />";
}
$sql = "SELECT poster_id
FROM " . _TABLE_POSTS . "
ORDER BY post_time DESC ";
echo $sql . "<br />" ;
if ($result = $db->query($sql)) {
$poster_id = array();
/* 获取相关联的数组 */
while ($row = $result->fetch_assoc()) {
$poster_id[] = $row['poster_id'];
}
print_r($poster_id);
/* 释放结果集 */
$result->close();
}
$sql = "SELECT *
FROM " . _TABLE_USERS . "
WHERE user_id IN (" . implode(",", $poster_id) . ") ";
echo "<br />" . $sql . "<br />";
if ($result = $db->query($sql)) {
$user_info = array();
/* 获取相关联的数组 */
while ($row = $result->fetch_assoc()) {
$user_info[] = array(
'username' => $row['username'],
'user_lastvisit' => FormatDate($row['user_lastvisit']),
'user_regdate' => FormatDate($row['user_regdate']),
'user_posts' => $row['user_posts'],
'user_lang' => $row['user_lang']
);
}
print_r($user_info) . "<br />";
/* 释放结果集 */
$result->close();
}
function FormatDate ($date) {
$format_date = date("Y-m-d h:i:s A", $date);
return $format_date;
}
?>
[/code:1] |
|