Jump to content

Archived

This topic is now archived and is closed to further replies.

ashton

Putting the new forum posts on the home page.

Recommended Posts

Alright I made a game, And the forums are self programmed meaning there not PHPBB forums, there just forums programmed with php, I have seen on websites how on the home page they display new posts, most recent etc. could anyone show me how to set one of those up?

Share this post


Link to post
Share on other sites
easy, do a select statement, have something in the database to differentiate, and do some calls to the db, just limit them so they don't overwhelm the visitor, like 20-30 per page.

Share this post


Link to post
Share on other sites
Hmm easier said that done, do you think you could help me out please, like how to code this etc. If you have aim: Ashtonhy or Over Email: ashtonhy@gmail.com  ??

Share this post


Link to post
Share on other sites
well for most recent, you would probably want to have the date logged when they post, sort  by date, like have a field called
postdate
have it put a time stamp there whenever they post
then on the homepage
have
$select = "SELECT * FROM tablename SORT BY postdate LIMIT 4;";
$query = mysql_query($select);
while ($row = mysql_fetch_array) {
// whatever to display
$controller = true; // or whatever variable
}
if ($controller != true) {
echo "There are no recent entries";
}
you probably wouldn't need the message if it's a forum though because there will always be recent entries, just the last 3 posted entries.

Share this post


Link to post
Share on other sites
Alright that looks good, but another question to display time, Because I have it displaying date, I would add a new field in the forum Table, but then how would I go about scripting that?

Share this post


Link to post
Share on other sites
table field name could be timeentry
$variable = time();
to display it
it's the same thing
$select = "SELECT * FROM tablename SORT BY postdate, timeentry LIMIT 4;";
I don't remember what goes in between those and I don't have time to check it's either
postdate AND timeentry
postdate OR time entry
postdate, time entry
it's one of the three.

Share this post


Link to post
Share on other sites
$select = "SELECT * FROM tablename SORT BY postdate LIMIT 4;";
$query = mysql_query($select);
while ($row = mysql_fetch_array) {
// whatever to display
$controller = true; // or whatever variable
}
if ($controller != true) {
echo "There are no recent entries";
}

Alright were it says "what ever to display" what exactly would go there?

Share this post


Link to post
Share on other sites
Oh and btw Im liking this site allready, thank you, business man your very helpfull!  ;D

Share this post


Link to post
Share on other sites
[code]It depends on how you wanted to display it, with tables it would be like
<?php
echo "<table>";
while ($row = mysql_fetch_array) {
echo "<tr><td>$variable</td></tr>";
$controller = true; // or whatever variable
}
echo "</table>";// tables outside of while, or it redoes table every circle through
?>[/code]
Just put the data in a formatted table, I can't do it for you, ebcause I don't have time and because I don't know how many fields you have, or you can use lists
[code]<?php
echo "<ul>" or echo "<ol>" // more of ul
while ($row = mysql_fetch_array) {
echo "<li>{variablename}</li>";
echo "<li>{varieblename2}</li>";
$controller = true; // or whatever variable
}
echo "<ul" or echo "<ol>" // more of ul[/code]
of course each call you make to the db variable you have to use the variable you used to access it, in this case it would be
$row['variablename']
or
$row['variablenamer']
when extrapolating they teach you to leave off the ' ' like
$row[variablename]
$row[variablename2]

Share this post


Link to post
Share on other sites
Parse error: parse error, unexpected '}' in /home/spxxxrw/public_html/mf/recentforum.php on line 9

<?php

$dbh=mysql_connect ("localhost", "spxxxrw_Axxxxn", "asxxxxxxx96") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("spyderw_dk");

$select = mysql_query("SELECT author,newpostdate,title, FROM spxxxxxw_forum ORDER BY `newpostdate` DESC LIMIT 3");
$total=1;
while($row = mysql_fetch_array($select))
}
if(isset($_GET['display'])) echo $recentforum;
?>


Any idea whats wronge with it?

"xxx" added for secur.

Share this post


Link to post
Share on other sites
[code]
<?php
$dbh=mysql_connect ("localhost", "spxxxrw_Axxxxn", "asxxxxxxx96") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("spyderw_dk");

$select = mysql_query("SELECT author,newpostdate,title, FROM spxxxxxw_forum ORDER BY `newpostdate` DESC LIMIT 3");
$total=1;
while($row = mysql_fetch_array($select)) {
}
if(isset($_GET['display'])) echo $recentforum;
?>
[/code]

Share this post


Link to post
Share on other sites
[code]if(isset($_GET['display'])) echo $recentforum;[/code]
That is not good practice, I was shown this before, someone corrected if not I would have made a grave mistake
it's always
[code]<?php
if (isset($get['display'])) {
echo $recentforum; // even here I like echo "{$recentforum}";  just depends on preference
}
// or
if (isset($get['display']))
{
echo $recentforum;
}
// I prefer the top
?>[/code]

Share this post


Link to post
Share on other sites
I put in what you gave me and got this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/spyderw/public_html/mf/recentforum.php on line 7

<?php
$dbh=mysql_connect ("localhost", "spyxxxton", "ashtxxx596") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("spydxxxk");

$select = mysql_query("SELECT author,newpostdate,title, FROM spydexxxum ORDER BY `newpostdate` DESC LIMIT 3");
$total=1;
while($row = mysql_fetch_array($select)) {
}
if(isset($_GET['display'])) echo $recentforum;
?>

Share this post


Link to post
Share on other sites
Parse error: parse error, unexpected $ in /home/spyderw/public_html/mf/recentforum.php on line 11

[code]<?php
$dbh=mysql_connect ("localhost", "spyderw_Ashton", "ashton2004596") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("spyderw_dk");

$select = mysql_query("SELECT author,newpostdate,title, FROM spyderw_forum ORDER BY `newpostdate` DESC LIMIT 3");
$total=1;
while($row = mysql_fetch_array($select)) {
}
if (isset($get['display'])) {
echo $recentforum; // even here I like echo "{$recentforum}";
?>[/code]

Share this post


Link to post
Share on other sites
[code]<?php
$dbh=mysql_connect ("localhost", "spyderw_Ashton", "ashton2004596") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("spyderw_dk");

$select = mysql_query("SELECT author,newpostdate,title, FROM spyderw_forum ORDER BY `newpostdate` DESC LIMIT 3");
$total=1;
while($row = mysql_fetch_array($select)) {
}
if (isset($get['display'])) {
echo $recentforum; // even here I like echo "{$recentforum}";
}
?>[/code]

Share this post


Link to post
Share on other sites
[code]<?php
$dbh=mysql_connect ("localhost", "spyderw_Ashton", "ashton2004596") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("spyderw_dk");

$select = mysql_query("SELECT author,newpostdate,title, FROM spyderw_forum ORDER BY `newpostdate` DESC LIMIT 3");
$total=1;
while($row = mysql_fetch_array($select)) {
}
if (isset($get['display'])) {
echo $recentforum; // even here I like echo "{$recentforum}";
}
?>[/code]
The code here doens't make sense to me though, your while statement is doing absolutely nothing.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.