Jump to content


Photo

Please help with using a php script on an html page...


  • Please log in to reply
14 replies to this topic

#1 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 July 2006 - 01:57 AM

God, I hope someone here can help me. I have been at this for the better part of today. Please forgive me if I have posted this in the wrong section....

Let me first say that I am a newbie with php so I hope my search for help forums has brought me to the right place.

The script I am trying to use is this:
------------------------------------------------
<?php
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
#   Applet  :   phpBB Latest Topic Displayer
#   Author  :   Jonathan Wolf <jonathanw@hotmail.com>, M.S.
#   Version :   v1.0 (2-20-06)
#   Changes :   v1.0 (2-20-06): Brand new.
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#

#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Control Constants
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#

// forum_id to grab topics from (must be a valid forum_id integer)
$forum_id = 3;

// How many of the newest topics to display
$limit_count = 5;

// Date and time format (used in PHP strftime() routine)
$date_time_format = "%b %e at %I:%M %p";    // e.x. 20 Feb 12:29 am

// Path to phpBB's base directory (usually "forum/" or "phpBB/")
// Note: This is !required! to be set correctly for this script to work
// (phpBB's include files will reference this variable many times).
$phpbb_root_path = "forum/";

#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# phpBB Connection Section
# This will give us a MySQL database connection ($db) to work with that
# is already initialized with the correct phpBB database for access.
# This also gives us some useful setup values such as the table prefix.
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
if(!defined("IN_PHPBB"))
{
  define("IN_PHPBB", true);
  include($phpbb_root_path . "extension.inc");
  include($phpbb_root_path . "common.".$phpEx);
  include($phpbb_root_path . "config.".$phpEx);
}

if($db)     // Database connection check
{
    #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
    # Database Query Section
    #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
    // Grab our topics using a singular query
    $topics_query = $db->sql_query("
        SELECT
            {$table_prefix}topics.topic_title,
            {$table_prefix}users.username AS poster_name,
            {$table_prefix}topics.topic_time,
            {$table_prefix}posts_text.post_text AS topic_text,
            {$table_prefix}topics.topic_views,
            {$table_prefix}topics.topic_replies,
            {$table_prefix}topics.topic_id,
            {$table_prefix}posts_text.post_id,
            {$table_prefix}topics.topic_poster AS poster_id
        FROM
            {$table_prefix}topics,
            {$table_prefix}users,
            {$table_prefix}posts_text
        WHERE
            {$table_prefix}topics.forum_id = {$forum_id} AND
            {$table_prefix}users.user_id =
                {$table_prefix}topics.topic_poster AND
            {$table_prefix}posts_text.post_id =
                {$table_prefix}topics.topic_first_post_id
        ORDER BY topic_time DESC
        LIMIT {$limit_count};");
    
    #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
    # Parsing Section
    #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
    // Topic query-result existance check and non-zero row count check
    if($topics_query && mysql_num_rows($topics_query))
    {
        // Now go through all our selected topics for processing and display
        while($topic_entry = $db->sql_fetchrow($topics_query))
        {
            // The first thing we have to do is pre-process some things...
            // The post_text needs to have its BB-code replaced with actual
            // HTML code, which is a bit tricky and involves some fancy foot
            // work. Some of the following processing code is, as mentioned,
            // adapted from clericvash's "Topic Extraction" script. Cheers.
            
            // Set up some easy to use variables for parsing and displaying.
            $topic_title = $topic_entry["topic_title"];
            $poster_name = $topic_entry["poster_name"];
            $topic_time = strftime($date_time_format, $topic_entry["topic_time"]);
            $topic_text = $topic_entry["topic_text"];
            $topic_views = $topic_entry["topic_views"];
            $topic_replies = $topic_entry["topic_replies"];
            $topic_id = $topic_entry["topic_id"];
            $post_id = $topic_entry["post_id"];
            $poster_id = $topic_entry["poster_id"];
            $view_link = "{$phpbb_root_path}viewtopic.{$phpEx}?p={$post_id}";
            $reply_link = "{$phpbb_root_path}posting.{$phpEx}?mode=reply&t={$topic_id}";
            $poster_link = "{$phpbb_root_path}profile.{$phpEx}?mode=viewprofile&u={$poster_id}";
            
            // BB-Code processing
            
            // Extra character removal (these characters are identifiers that
            // are concatenated into the BB-code commands themselves in order
            // to help phpBB track appropriated opening and closing commands).
            $topic_text = preg_replace("/\:[0-9a-z\:]+\]/si", "]", $topic_text);
            // Bold
            $topic_text = str_replace("[b]", "<B>", $topic_text);
            $topic_text = str_replace("[/b]", "</B>", $topic_text);
            // Italics
            $topic_text = str_replace("[i]", "<I>", $topic_text);
            $topic_text = str_replace("[/i]", "</I>", $topic_text);
            // Underline
            $topic_text = str_replace("[u]", "<U>", $topic_text);
            $topic_text = str_replace("[/u]", "</U>", $topic_text);
            // Quote (style #1)
            $topic_text = preg_replace("/\[quote=(.*)\](.*)\[\/quote\]/Usi", "<DIV STYLE=\"padding: 7px\">$2</DIV>", $topic_text);
            // Quote (style #2)
            $topic_text = str_replace("[quote]", "<B>Quote:</B><BR><I>", $topic_text);
            $topic_text = str_replace("[/quote]", "</I>", $topic_text);
            // Code
            $topic_text = str_replace("[code]", "<B>Code:</B><BR><I>", $topic_text);
            $topic_text = str_replace("[/code]", "</I>", $topic_text);
            // List
            $topic_text = preg_replace("/\[list\](.*)\[\/list\]/si", "<DIV STYLE=\"padding: 7px\">$1</DIV>", $topic_text);
            $topic_text = preg_replace("/\[list=(.*)\](.*)\[\/list\]/si", "<DIV STYLE=\"padding: 7px\">$1</DIV>", $topic_text);
            // Image
            $topic_text = str_replace("[img]http://", "<IMG SRC=\"", $topic_text);
            $topic_text = str_replace("[/img]", "\" ALT=\"Image\">", $topic_text);
            // URL
            $topic_text = preg_replace("/\[url\](.*)\[\/url\]/Usi", "<A HREF=\"$1\" TARGET=\"_blank\">$1</A>", $topic_text);
            $topic_text = preg_replace("/\[url=http://(.*)\](.*)\[\/url\]/Usi", "<A HREF=\"$2\" TARGET=\"_blank\">$2</A>", $topic_text);
            // Endlines
            $topic_text = str_replace("\n", "<BR>\n", $topic_text);
            
            #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
            # Displaying Section
            # Modify this section to your liking. Currently, this section
            # just contains a dummy displayer. The following variables have
            # been pre-initialized to help with this section, and include:
            # $topic_title - (text) Title of topic
            # $poster_name - (text) Username of original poster
            # $topic_time - (text) Time of post creation (converted string)
            # $topic_text - (text) Actual text of the topic (already in HTML)
            # $topic_views - (int) Number of topic views (in the forum)
            # $topic_replies - (int) Number of replies for topic
            # $topic_id - (int) Topic's id # (from database)
            # $post_id - (int) Post's id # (from database)
            # $poster_id - (int) Poster's user id # (from database)
            # $view_link - (text) An http link to the forum view topic page
            # $reply_link - (text) An http link to the forum reply-to page
            # $poster_link - (text) An http link to the poster's info page
            #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
            // Head banner (poster, date)
			echo("<table>\n");
			echo("<tr>\n");
			echo("<td bgcolor=4D5459>\n");
                        echo("<A HREF=\"{$view_link}\" TARGET=\"_blank\">{$topic_title}</A> <br> Posted on {$topic_time}<BR>\n");
			echo("</td>\n");
			echo("</tr>\n");
			echo("</table>\n");
        }
    }
    else
    {
        // No topics exist in this forum. Display some sort of error message.
        echo("<P>No topics exist in the forum.<BR>\n");
    }
}
?>
-----------------------------------------------------



I am trying to add this to a page I have been working on by using iframe:
<tr> 
                      <td bgcolor="4D5459"><br><br>
                        <img src="images/kimscorner.gif" border="0"><br>
                        <iframe width=245 src="grabber1.php" align=middle frameborder=0 scrolling=auto name=viewpoint></iframe></td>
                    </tr>


1st question, Is there a better way to do this?

2nd question, How can I, or will someone help me to change the font color and size of the font that is displayed by the php script? ({$topic_title} & {$topic_time})

3rd question, If you look at the working demo with ie there is a white bg that I cannot get rid of, but with firefox the white bg is not there. http://www.midwestch...com/index2.html
My plan is to get rid of the scroll bar and still show 5 latest topics without making the page any bigger then it is....


Thanks in Advance....

zach

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 10 July 2006 - 02:05 AM

1. You should try setting this up in a div and using and include instead of an iframe.
2. You can change the colors in the css files that were included in your forum
3. If you use a div and include it should get rid of any extra space IE is putting in there.

Hope that helped.

-Chris

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 10 July 2006 - 02:05 AM

There is an entrie forum dedicated to help with third party scripts, this is the wrong place to post such requests.

#4 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 July 2006 - 02:18 AM

1. You should try setting this up in a div and using and include instead of an iframe.
2. You can change the colors in the css files that were included in your forum
3. If you use a div and include it should get rid of any extra space IE is putting in there.

Hope that helped.

-Chris



I will try changing to a div....

As far as my forums go.... this script did not come with the phpBB forums... So I do not think it is reading the css from the forums...

Thanks

zach

#5 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 July 2006 - 02:19 AM

There is an entrie forum dedicated to help with third party scripts, this is the wrong place to post such requests.



That is why I said I was sorry if it was in the wrong area.... maybe a mod can move this to the right section for me...


zach

#6 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 10 July 2006 - 02:22 AM

When you set up the div, assign it an id and in your css make the output that you want with that id. That will over ride whatever css it is reading from now.

-Chris

#7 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 July 2006 - 02:29 AM

When you set up the div, assign it an id and in your css make the output that you want with that id. That will over ride whatever css it is reading from now.

-Chris



Yea, that is all foreign language to me..... I think I am about to throw in the white towel here... I have been looking at this code all day... I have been to 3 php help forums... and still can't figure it out...


Thanks... I will check back here tomorrow..... Thanks for looking..



zach

#8 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 July 2006 - 01:31 AM

When you set up the div, assign it an id and in your css make the output that you want with that id. That will over ride whatever css it is reading from now.

-Chris


Would something like this work?

echo(" <span class='STYLE_NAME'><A HREF=\"{$view_link}\" TARGET=\"_blank\">{$topic_title}</A> <br> Posted on {$topic_time}</span><BR>\n");

And then can I add the style in the index.html page, or do I need to actually create a

<style>...... </style>

in the php script somewhere?




zach

#9 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 July 2006 - 01:32 AM

To the Admins of these forums...

I now know you have an area for third party script help.... please feel free to move this there.... I do not want to re-post it there and then have 2 post going...


Thank You
zach

#10 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 11 July 2006 - 03:09 AM

What you wrote first should work for you
echo(" <span class='STYLE_NAME'><A HREF=\"{$view_link}\" TARGET=\"_blank\">{$topic_title}</A> <br> Posted on {$topic_time}</span><BR>\n");

-Chris

#11 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 July 2006 - 10:26 AM

What you wrote first should work for you

echo(" <span class='STYLE_NAME'><A HREF=\"{$view_link}\" TARGET=\"_blank\">{$topic_title}</A> <br> Posted on {$topic_time}</span><BR>\n");

-Chris



Thanks.... I actually got the font and colors changed for the most part. I had to use a style tag with the values in-line....

But now I can't seem to get it to work in my html document with a php include tag. Not sure what is wrong.... but now I would like to get away from using an iframe.



zach

#12 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 11 July 2006 - 01:05 PM

Instead of where you have the iframe put this:

<div id="top_5" style="width:100;height:100;overflow:auto;"><?php include "your_top_five_script.php"; ?></div>

change the height and width to whatever you want.

-Chris

#13 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 July 2006 - 12:11 AM

Chris

OK, this is what I have now, and it still did not work.

<tr> 
                      <td><br><br>
                        <img src="images/kimscorner.gif" border="0" align="top"><br>
                        <div id="top_5" style="width:245;height:225;overflow:auto;"><?php include "http://midwestcheeranddance.com/grabber1.php"; ?></div></td>
                    </tr>


it looks as if it has created the space, but nothing from the script is showing.


Any ideas?




zach

#14 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 July 2006 - 10:10 PM

Anyone know why this does not work?





zach

#15 lazzeristudios

lazzeristudios
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 July 2006 - 01:49 AM

nevermind.... I just need to parse my html to php.........




zach




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users