PHP的MYSQL问题

来源:百度知道 编辑:UC知道 时间:2024/05/11 15:48:29
以下代码只调用了一个数据库pw_threads的内容我想调两个表的内容下面代码应该怎么写啊
function bbs_title($fid,$len,$num="10")
{
global $db;
[color=Blue]$query = $db->query("SELECT tid, fid, subject, authorid, postdate
FROM `pw_threads` WHERE fid=$fid ORDER BY `tid` DESC LIMIT 0, $num");[/color]
while ($threads = $db->fetch_array($query)){
$threads['subject'] = substrs($threads['subject'], $len);
$article .= "> <a href='bbs/read.php?tid=$threads[tid]'

target='_blank'>$threads[subject]</a><br>\n";
}
return $article;
}

//使用方法如:
$shownew=bbs_title(60,50,100);
echo "$shownew";
?>

同时调用两个数据库的

$query = $db->query("SELECT tid, fid, subject, authorid, postdate
FROM `pw_threads` WHERE fid=$fid ORDER BY `tid` DESC LIMIT 0, $num");[/color]
while ($threads = $db->fetch_array($query)){
$threads['subject'] = substrs($threads['subject'], $len);
$article .= "> <a href='bbs/read.php?tid=$threads[tid]'

target='_blank'>$threads[subject]</a><br>\n";
}

你把这一段在复制一下,把$Query改为$Query1,里面的SQL语句改为读取第二个表的SQL,不就可以了吗?

如果你要在一条SQL里面取两个表的内容,那就不用复制上面代码了,直接改Select的SQL语句就可以了。至于要怎么改,因为不清楚你的两个表的表结构,就不答了。