1 (edited by Arne 2003-08-26 17:20)

Topic: Recent Discussions on Frontpages

Okay, I'm not a coder at all but I took the time to create some code for "recent discussions" on front pages:

I used it in a seperate file like _recentdiscussions.php which I included then into the CMS:

<? 

  $MYSQL_HOST = 'localhost';
  $MYSQL_USER = '';
  $MYSQL_PASSWORD = '';
  $MYSQL_DATABASE = '';


  $mySQLconerror = "<h1>mySQL server died unexpectly</h1><h3>There was an internal error processing your request!</h3>Click <a href='javascript:location.href=location.href'>refresh</a> to resubmit the information.<br>If the error persists contact your system administrator or the support team.</h3>";
  $mySQLdberror  = "<h1>mySQL server internal error</h1><h3>Could not select the database! The database might be deleted or in error code.</h3>Click <a href='javascript:location.href=location.href'>refresh</a> to resubmit the information.<br>If the error persists contact your system administrator or the support team.</h3>";

  function ExecuteSQL($query,$db_conn) {
    $result = mysql_query($query,$db_conn);
    if (mysql_errno() != "0") { 
      echo "<div class='error'><br>mySQL ERROR # ".mysql_errno()." <br> ".mysql_error()."<br><br><br><button hidefocus onClick='history.back(-1)' class='menu1'>Back</button><br><br></div>\n";
      die();
    }
    else {
      return $result;
    }
  }



  $numberOfPosts   = 5;
  $numberOfCharacters = 85;




  $connection = @mysql_connect("$MYSQL_HOST", "$MYSQL_USER", "$MYSQL_PASSWORD") or die("$mySQLconerror");
  $db = @mysql_select_db("$MYSQL_DATABASE", $connection) or die("$mySQLdberror");
  $sql = "SELECT id,poster,message,posted,topic_id FROM posts ORDER by posted DESC LIMIT 0,".$numberOfPosts; 
  $result = ExecuteSQL($sql,$connection);

  $connection1 = @mysql_connect("$MYSQL_HOST", "$MYSQL_USER", "$MYSQL_PASSWORD") or die("$mySQLconerror");
  $db1 = @mysql_select_db("$MYSQL_DATABASE", $connection1) or die("$mySQLdberror");

  while ($row = mysql_fetch_array($result)) {
  
    $sql = "SELECT subject  FROM topics WHERE id='".$row['topic_id']."'"; 
    $res = ExecuteSQL($sql,$connection);
    $tmp = mysql_fetch_array($res);
    $topic  = $tmp["subject"];
    $thread  = $row["id"]; 
    $myname  = $row["poster"]; 
    $ctext  = $row["message"]; 
    $ctext = ereg_replace("^(.{1,$numberOfCharacters})[ .,].*", "\\1", $ctext);


    $myname  = str_replace("<","",$myname);
    $myname  = str_replace(">","",$myname);
    $ctext  = strip_tags($ctext);

    $topic=substr($topic,0,25)."...";

/*
    $sql1 = "SELECT threadid,forumid FROM itaf_thread where threadid='{$thread}' limit 0,1"; 
    $result1 = ExecuteSQL($sql1,$connection1);
    while ($row1 = mysql_fetch_array($result1)) {
      $forum = $row1["forumid"];
    }
*/
    $output = "<a href=\"/forum/viewtopic.php?pid={$thread}#{$thread}\"><b>{$topic}</b></a><br><b>{$myname} says:</b> <i>{$ctext}...</i>";
    $output = str_replace("\n","",$output);
    $output = str_replace("\r","",$output);

    print $output."<p>";
  }

?>

The result can be seen here http://www.ppcw.net/
Oh yes, again - I have more or less no coding skills so the code above might be completely crap - feel free to improve and modify it... ;-)

Cheers ~ Arne

Re: Recent Discussions on Frontpages

Looks good. One thing though, you don't have to connect and select DB twice. I think you can safely remove the two rows after the first ExecuteSQL(). Or did I miss something?

I'm actually planning on doing something similar for PunBB 1.1 :)

Edit: BTW, that's a nice website and forum you've got there. Nice to see you've modified the look a little :)

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3

Re: Recent Discussions on Frontpages

Kennel wrote:

Looks good. One thing though, you don't have to connect and select DB twice. I think you can safely remove the two rows after the first ExecuteSQL(). Or did I miss something?

Hmmm... No, seems you are right. Why the hell I've added it!? ;-)
Well, if a non-coder starts coding... Maybe it's because I'm German and I want to make sure it really connects!? ;-) LOL...

I'm actually planning on doing something similar for PunBB 1.1 smile

That's great. I see my code as a kind of temp solution anyway...

Edit: BTW, that's a nice website and forum you've got there. Nice to see you've modified the look a little smile

Thanks but the Forum integration is still far away from what I'm planing and working on right now. Currently I'm moving to a new server and there I'm working on a much smother integration. What you see on the "old" (current) site is just a bloody fast workaround I made because I removed my old Forum and wanted to make sure to have a Forum online anyway.

Cheers ~ Arne

Re: Recent Discussions on Frontpages

Arne wrote:

Maybe it's because I'm German and I want to make sure it really connects!? ;-) LOL...

Haha, yeah! :)

"Programming is like sex: one mistake and you have to support it for the rest of your life."

5 (edited by Frank H 2003-08-26 20:03)

Re: Recent Discussions on Frontpages

nice site, and a nice script.

This thing was abit comic though (default timestamp if no cookie is found or somehting?)

"Welcome back! You last visited on 01 Jan 1970 @ 01:00."
I was born over 9 years later big_smile

6

Re: Recent Discussions on Frontpages

Hehehe... Yes, it's an ugly bug of that script... Will be changed with "PPCW.Net 2003" anyway... wink
Even me was born one year and 47 days later... smile

Cheers ~ Arne

Re: Recent Discussions on Frontpages

where do I ad this in main page index of the dite (not forum)

Re: Recent Discussions on Frontpages

That is 2 year old code
And this is a 2 year old thread
You can't just add it in, it most likely won't work

Re: Recent Discussions on Frontpages

ok so where's the new one big_smile

Re: Recent Discussions on Frontpages

Maybe there isn't new code, but why can't you find it yourself if there is?

Re: Recent Discussions on Frontpages

I did serch for it no results

Re: Recent Discussions on Frontpages

I'd suggest taking a look at extern.php