Jump to content


Photo

Putting the new forum posts on the home page.


  • Please log in to reply
16 replies to this topic

#1 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:02 PM

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?

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:03 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:06 PM

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  ??

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:07 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:09 PM

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?

#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:12 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#7 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:14 PM

$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?

#8 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:16 PM

Oh and btw Im liking this site allready, thank you, business man your very helpfull!  ;D

#9 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:19 PM

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
?>
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
<?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
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]

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#10 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:36 PM

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.

#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:38 PM

<?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;
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:41 PM

if(isset($_GET['display'])) echo $recentforum;
That is not good practice, I was shown this before, someone corrected if not I would have made a grave mistake
it's always
<?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
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#13 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:42 PM

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;
?>

#14 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:43 PM

ooh so your uptop post is prob my problem?

#15 ashton

ashton
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 28 July 2006 - 02:47 PM

Parse error: parse error, unexpected $ in /home/spyderw/public_html/mf/recentforum.php on line 11

<?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}"; 
?>


#16 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:48 PM

<?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}"; 
}
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#17 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:49 PM

<?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}"; 
}
?>
The code here doens't make sense to me though, your while statement is doing absolutely nothing.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users