PDA

View Full Version : Some code in my phpinclude_start - how would you rewrite this code?


Jenta
05-04-2005, 04:02 PM
Am I doing this the most efficient and proper way? I don't trust myself much :nervous:

It works but perhaps it's noobish? Can u tell me how to make it more correct?

I'm mostly referring to stuff like changing some things to OR, AND, ELSE and combing it into one statement or whatever.

Will doing so make it parse faster and more effieciently?



// question 1
if (!defined('IN_PORTAL_AREA')) {

// question 2
if (THIS_SCRIPT == 'index')
{
// do something
$lifetime_posts = $DB_site->query_first("SELECT post.postid
FROM " . TABLE_PREFIX . "post AS post
ORDER BY post.postid DESC
LIMIT 1");

$lifetime_threads = $DB_site->query_first("SELECT thread.threadid
FROM " . TABLE_PREFIX . "thread AS thread
ORDER BY thread.threadid DESC
LIMIT 1");
}

// question 3
if (THIS_SCRIPT == 'index' OR THIS_SCRIPT == 'forumdisplay')
{
// do something
$forumcounts= $DB_site->query("SELECT forumid, replycount, threadcount
FROM " . TABLE_PREFIX . "forum
");
while ($forumcount = $DB_site->fetch_array($forumcounts))
{
$forumreply[$forumcount[forumid]] = $forumcount[replycount];
$forumthread[$forumcount[forumid]] = $forumcount[threadcount];
}
}

// question 4
if ($bbuserinfo['userid'] != 1) {
// question 5
if (THIS_SCRIPT == 'adv_index')
{
// do something
include("./forums/statistic_counter.php");
}
// question 6
if (THIS_SCRIPT == 'index')
{
// do something
include("./statistic_counter.php");
}

}

// question 7
if (defined('IN_PORTAL_AREA')) {
// do something
require_once('./global.php');
}



thanks!

sabret00the
05-05-2005, 07:09 PM
that's not bad at all :)

although i'm not sure about question 7, is that the vBglobal.php you're requiring?

Jenta
05-06-2005, 08:13 AM
7 is vbportal which i have now abandoned all that !defined in portal area is gone now

good addon but i dont have the patience to do all the work to make it work like i want
ill just add 10 individual hacks to replace its funcionability :)

sabret00the
05-06-2005, 10:25 AM
good luck :)