PDA

View Full Version : Help with news page hack I made


DionDev
09-21-2008, 03:53 PM
I am looking for some help with this. Now it works, but it doesn't seem to be as efficient as I would like it to be. I mean sometimes it takes a couple of seconds to display the page. The execution time is what I am worried about.

Could any PHP gurus give some input as to how I could improve this news page script I wrote? (it grabs news from a specified forum and spits it out onto a php page)


<?php

chdir('./forums');
require_once('./global.php');
require_once('./includes/class_bbcode.php');

$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$dbhost = 'localhost';
$dbname = '*****';
$dbuser = '*****';
$dbpass = '*****';

mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);

$sql = 'SELECT post.pagetext, thread.*
FROM post AS post, thread AS thread
LEFT JOIN forum AS forum ON (forum.forumid = thread.forumid)
WHERE FIND_IN_SET(4, forum.parentlist) AND post.postid = thread.firstpostid
ORDER BY thread.dateline DESC
LIMIT 5';

$sqlresult = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($sqlresult);

while ($row = mysql_fetch_array($sqlresult))
{
$subject = $row['title'];
$poster = $row['postusername'];
$posterid = $row['postuserid'];
$time = date("D, M j, Y", $row['dateline']);
$replies = $row['replycount'];
$id = $row['threadid'];
$text = $parser->do_parse($row['pagetext'], true, true, true, true, true, false);

if ($replies == 1)
$replytext = 'reply';
else
$replytext = 'replies';

echo "<b>$subject</b>";

echo '<br>';

echo '<font style="font-size: 8pt;">';
echo "Posted by <a href=\"forums/member.php?u=$posterid\">$poster</a> on $time (<a href=\"forums/showthread.php?t=$id\">$replies $replytext</a>)";
echo '</font>';

echo '<br><br>';

echo $text;
}

echo '<br><br><div style="float: right;"><a href="forums/forumdisplay.php?f=4">News Archive Forum</a></div>';

?>

MoT3rror
09-23-2008, 02:38 AM
One it is best to use vBulletin db functions so you only use one database connection.
https://vborg.vbsupport.ru/showthread.php?t=98047&highlight=database+class

But if you want to stay with the mysql default functions, it would probably be best to change your code to this.


chdir('./forums');
require_once('./global.php');
require_once('./includes/class_bbcode.php');

$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());

$dbhost = 'localhost';
$dbname = '*****';
$dbuser = '*****';
$dbpass = '*****';

$dbconnection = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $dbconnection);

$sql = 'SELECT post.pagetext, thread.*
FROM post AS post, thread AS thread
LEFT JOIN forum AS forum ON (forum.forumid = thread.forumid)
WHERE FIND_IN_SET(4, forum.parentlist) AND post.postid = thread.firstpostid
ORDER BY thread.dateline DESC
LIMIT 5';

$sqlresult = mysql_query($sql, $dbconnection) or die(mysql_error());
$count = mysql_num_rows($sqlresult);

while ($row = mysql_fetch_array($sqlresult))
{
$subject = $row['title'];
$poster = $row['postusername'];
$posterid = $row['postuserid'];
$time = date("D, M j, Y", $row['dateline']);
$replies = $row['replycount'];
$id = $row['threadid'];
$text = $parser->do_parse($row['pagetext'], true, true, true, true, true, false);

if ($replies == 1)
$replytext = 'reply';
else
$replytext = 'replies';

echo "<b>$subject</b>";

echo '<br>';

echo '<font style="font-size: 8pt;">';
echo "Posted by <a href=\"forums/member.php?u=$posterid\">$poster</a> on $time (<a href=\"forums/showthread.php?t=$id\">$replies $replytext</a>)";
echo '</font>';

echo '<br><br>';

echo $text;
}

mysql_close($dbconnection);

echo '<br><br><div style="float: right;"><a href="forums/forumdisplay.php?f=4">News Archive Forum</a></div>';