Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying News on Homepage
#1
I want to use my own homepage, and put news from MyBB on it. Anyone wanna help?

Here is the page

http://www.techtabs.com/index.php

(I have tried and failed Sad)
Reply
#2
Try:
PHP Code:
<?php
$mysqlusername 
"";
$mysqlpassword "";
$mysqldbselect "";
$prefix "mybb_";
$fid "2";

mysql_select_db($mysqldbselectmysql_connect("localhost",$mysqlusername,$mysqlpassword));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE fid='".$fid."' AND visible='1' AND closed NOT LIKE 'moved|%'");
while(
$news mysql_fetch_array($query))
{
echo 
"<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
Change the 5 values at the top to suit you forums configuration. First three are you database name, database username, and database password to your mySQL server. The next is the table prefix. If you gave your forum a different prefix, change it so it works. Lastly, add the forum id you want to pull the announcements/news from.

That should work. I havn't tested it though.

Edit: That code above will output something similar:
Quote:Forum is now open | Posted by: Admin | Replies: 34
Welcome to the forum. I trust you will enjoy it. I'm running MyBB. You can find it at http://www.mybboard.com/. Its very professional and I will continue to keep up to date with it as it is free. If you have a server, I encourage you to try it out.
(details will change depending on the post and auther of coarse Big Grin)
Reply
#3
k776, I was also looking for a way to do that. I changed the variables, but I get this error.

Quote:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/x/s/xs/public_html/test/index.php on line 135

Any idea why? It seems to me that it can't do the query for some reason.
Reply
#4
Yea I got the same errors.
Reply
#5
Try this:
Code:
<?php
$mysqlhost = "localhost";
$mysqlusername = "";
$mysqlpassword = "";
$mysqldbselect = "";
$prefix = "mybb_";
$fid = "2";

mysql_connect($mysqlhost,$mysqlusername,$mysqlpassword);
mysql_select_db($mysqldbselect);

$query = mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE fid='".$fid."' AND visible='1' AND closed NOT LIKE 'moved|%'");
while($news = mysql_fetch_array($query))
{
echo "<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
Dennis Tsang
http://dennistt.net
Reply
#6
Odd still dosen't work even after modfcations. Any other ideas?
Reply
#7
Hmm. Run this (after chaning the 6 values to the correct details) and tell me the output.
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqlusername "";
$mysqlpassword "";
$mysqldbselect "";
$prefix "mybb_";
$fid "2";

mysql_select_db($mysqldbselectmysql_connect($mysqlhost,$mysqlusername,$mysqlpassword));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE fid='".$fid."' AND visible='1' AND closed NOT LIKE 'moved|%'") or die(mysql_error());
while(
$news mysql_fetch_array($query))
{
echo 
"<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
There doesn't actually seem to be anything wrong with it so I'm not sure why its not working.
Reply
#8
k776 Wrote:Hmm. Run this (after chaning the 6 values to the correct details) and tell me the output.
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqlusername "";
$mysqlpassword "";
$mysqldbselect "";
$prefix "mybb_";
$fid "2";

mysql_select_db($mysqldbselectmysql_connect($mysqlhost,$mysqlusername,$mysqlpassword));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE fid='".$fid."' AND visible='1' AND closed NOT LIKE 'moved|%'") or die(mysql_error());
while(
$news mysql_fetch_array($query))
{
echo 
"<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
There doesn't actually seem to be anything wrong with it so I'm not sure why its not working.
Causes:
Quote:Column: 'fid' in where clause is ambiguous
NetAdmin @ PharosIRC
irc.pharosirc.net
#Help,#lobby,#linux
MrStatic
Reply
#9
Yea thats what I get to any ideas?
Reply
#10
Alright Confused Try this
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqlusername "";
$mysqlpassword "";
$mysqldbselect "";
$prefix "mybb_";
$fid "2";

mysql_select_db($mysqldbselectmysql_connect($mysqlhost,$mysqlusername,$mysqlpassword));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE fid=$fid AND visible='1' AND closed NOT LIKE 'moved|%'") or die(mysql_error());
while(
$news mysql_fetch_array($query))
{
echo 
"<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
or if that doesn't work
PHP Code:
<?php
$mysqlhost 
"localhost";
$mysqlusername "";
$mysqlpassword "";
$mysqldbselect "";
$prefix "mybb_";

mysql_select_db($mysqldbselectmysql_connect($mysqlhost,$mysqlusername,$mysqlpassword));

$query mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.replies,p.message FROM ".$prefix."threads t LEFT JOIN ".$prefix."posts p ON (t.tid = p.tid) WHERE fid='2' AND visible='1' AND closed NOT LIKE 'moved|%'") or die(mysql_error());
while(
$news mysql_fetch_array($query))
{
echo 
"<a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | Posted by: <a href=\"./forum/member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> | Replies: <a href=\"./forum/showthread.php?tid=".$news['tid']."\">".$news['replies']."</a><hr />".$news['message']."<br /><br />";
}
?>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)