Log in

View Full Version : Can anyone see any problems with this code?


BigIke
03-21-2005, 07:07 PM
This code grabs the most recent post, author blah blah... I keep getting an error message that states:
Fatal error: Call to a member function on a non-object in /homepages/24/d116946458/htdocs/vb/modules/features.php on line 24

<?php

/* Needed for use without vBA
require_once('./global.php');
*/


/* ###### VARIOUS SETTINGS ###### */

$box_max_title_length=30;
$box_max_post_length=80;
$box_do_parse=0; /* Set to 1 to parse BBCODE */
$box_attachment_file="http://s116946478.onlinehome.us/vb/attachment.php?";

/* ###### GRABBING DATA ###### */

/* Only needed if you're going to be using bbcode */
if($box_do_parse==1){require_once('./includes/functions_bbcodeparse.php');}

/* Forum to Grab thread/post from */
$box_forumid_1=2;

/* Grabbing the thread */
$box_forumid_1thread = $DB_site->query_first("SELECT * FROM ".TABLE_PREFIX."thread
WHERE forumid = '$box_forumid_1' ORDER BY thread.dateline DESC ");

/* Grabbing the first post */
$box_forumid_1_first_post=$DB_site->query_first("SELECT * FROM ".TABLE_PREFIX."post
WHERE threadid = '$box_forumid_1thread[threadid]' ORDER BY dateline ASC");

/* Grabbing the first attachment */
$box_forumid_1_image=$DB_site->query_first("SELECT * FROM ".TABLE_PREFIX."attachment
WHERE postid = '$box_forumid_1_first_post[postid]' ORDER BY dateline DESC");

$image1=$box_forumid_1_image['attachmentid'];

/* ###### FORMATING DATA ###### */

/* Max title length */
if(strlen($box_forumid_1thread[title])>$box_max_title_length){
$box_forumid_1thread[title]=substr($box_forumid_1thread[title], 0, $box_max_title_length);
}

/* Max post length */
if($box_forumid_1_first_post[pagetext]>$box_max_post_length){
$box_forumid_1_first_post[pagetext]=substr($box_forumid_1_first_post[pagetext], 0, $box_max_post_length);
}

/* Parse BBCODE if desired */
if($box_do_parse==1){
$box_forumid_1_first_post[pagetext]=parse_bbcode($box_forumid_1_first_post[pagetext]);
}

/* IMAGE CREATION */
$box_1_image="<img src='".$box_attachment_file."attachmentid=$img_m&stc=1' width='100' height='100' border='0'/>";

/* Template to use for data */
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_features') . '";');

?>

This guy has been giving me some problems, any help would be appreciated

amykhar
03-21-2005, 07:10 PM
put in global $DB_site; and see how that goes.

Deaths
03-21-2005, 07:21 PM
You need your global.php mate.
Change

/* Needed for use without vBA
require_once('./global.php');
*/
to

//Needed for use without vBA
require_once('./global.php');


;)

BigIke
03-21-2005, 08:59 PM
I've installed many hacks but for some reason, I can't get the path right for my global.php.. I have set it to /homepages/24/d116946458/htdocs/vb/global.php , but it now says
Fatal error: main(): Failed opening required './includes/init.php' (include_path='.:/usr/local/lib/php') in /homepages/24/d116946458/htdocs/vb/global.php on line 50I suspect my path in the features.php is wrong... But thats why I came to you guys, because you're the experts :glasses:

noppid
03-21-2005, 09:05 PM
Something else is assuming you are in the forums folder.

try ...

chdir("/homepages/24/d116946458/htdocs/vb");

Before your call to include global.

Deaths
03-21-2005, 09:06 PM
Heh :).

Are you coding a vBa cmps module?
Or is this a normal script, and you're using a cmps module as a guide?

BigIke
03-21-2005, 09:11 PM
Yeah, this is for a vBadvanced module at the top of my site. I made sure that I specified the forum to pull the objects from /* Forum to Grab thread/post from */
$box_forumid_1=2;Then, I made a template so that the "features.php" could be displayed in it.

Deaths
03-21-2005, 09:14 PM
Try filling in 2 instead of the variable, see what it gives.

BigIke
03-21-2005, 09:20 PM
NOPPID- you're the man. I put the chdir... before it, and now I don't receive an error message. One problem though, and I suspect it is with my template, but if you go to the homepage (http://s116946478.onlinehome.us/vb/cmps_index.php), well, you can see its kind of messed up.
My template goes something like this...<table align="center" border="0" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%">
<tr>
<td class="tcat">
<strong><span class="smallfont">$vba_options[portal_blockbullet] $vboptions[bbtitle]Features</strong></span>
</td>
</tr> <table align="center" border="0" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%">
<tr>
<td class="tcat">
<strong><span class="smallfont">$vba_options[portal_blockbullet] $vboptions[bbtitle]Features</strong></span>
</td>
</tr>
</table>
<table align="center" border="0" cellpadding="0" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%" height="600">
<tr>
<td class="alt1">
<div align="center"><iframe src="$vboptions[bburl]/modules/features.php" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div>
</td>
</tr>
</tbody>
</table>
</table>
<table align="center" border="0" cellpadding="0" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%" height="600">
<tr>
<td class="alt1">
<div align="center"><iframe src="$vboptions[bburl]http://s116946478.onlinehome.us/vb/modules/features.php" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></div>
</td>
</tr>
</tbody>
</table>
I wasn't sure how to include the features.php module without using an iframe, and I think that's what is causing the problems. By the way, thanks for everyones input so far.

Deaths
03-21-2005, 09:21 PM
Sorry, the board is unavailable at the moment while we are testing some functionality.

We will be back soon...

You can add it as a module, then let the file call the template...

BigIke
03-21-2005, 09:26 PM
So, I don't need the <iframe> part in there at all and have the module call adv_portal_features (the template)?

BTW: I opened the forum back up so you can see the problem occurring.

Everything is cool now. Thanks for all of your help

Deaths
03-22-2005, 08:30 AM
Yes, add your PHP file to your modules list, and it should work.

Have you pu the layout of your module in your PHP file? If so, place it in a template.

BigIke
03-22-2005, 11:14 PM
My only problem is that I am not sure how to format the template. The module is activated and it includes features.php, but I am unsure what to put in the template to display the information that the php script retrieves. Anyone have any ideas?

Deaths
03-23-2005, 10:41 AM
Post the script you coded here, else we can't help you.

BigIke
03-23-2005, 06:33 PM
It's the same one as above. Here it is
<?php

/* Needed for use without vBA
require_once('./global.php');
*/


/* ###### VARIOUS SETTINGS ###### */

$box_max_title_length=30;
$box_max_post_length=80;
$box_do_parse=0; /* Set to 1 to parse BBCODE */
$box_attachment_file="http://s116946478.onlinehome.us/vb/attachment.php?";

/* ###### GRABBING DATA ###### */

/* Only needed if you're going to be using bbcode */
if($box_do_parse==1){require_once('./includes/functions_bbcodeparse.php');}

/* Forum to Grab thread/post from */
$box_forumid_1=2;

/* Grabbing the thread */
$box_forumid_1thread = $DB_site->query_first("SELECT * FROM ".TABLE_PREFIX."thread
WHERE forumid = '$box_forumid_1' ORDER BY thread.dateline DESC ");

/* Grabbing the first post */
$box_forumid_1_first_post=$DB_site->query_first("SELECT * FROM ".TABLE_PREFIX."post
WHERE threadid = '$box_forumid_1thread[threadid]' ORDER BY dateline ASC");

/* Grabbing the first attachment */
$box_forumid_1_image=$DB_site->query_first("SELECT * FROM ".TABLE_PREFIX."attachment
WHERE postid = '$box_forumid_1_first_post[postid]' ORDER BY dateline DESC");

$image1=$box_forumid_1_image['attachmentid'];

/* ###### FORMATING DATA ###### */

/* Max title length */
if(strlen($box_forumid_1thread[title])>$box_max_title_length){
$box_forumid_1thread[title]=substr($box_forumid_1thread[title], 0, $box_max_title_length);
}

/* Max post length */
if($box_forumid_1_first_post[pagetext]>$box_max_post_length){
$box_forumid_1_first_post[pagetext]=substr($box_forumid_1_first_post[pagetext], 0, $box_max_post_length);
}

/* Parse BBCODE if desired */
if($box_do_parse==1){
$box_forumid_1_first_post[pagetext]=parse_bbcode($box_forumid_1_first_post[pagetext]);
}

/* IMAGE CREATION */
$box_1_image="<img src='".$box_attachment_file."attachmentid=$img_m&stc=1' width='100' height='100' border='0'/>";

/* Template to use for data */
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_features') . '";');

?>

Deaths
03-24-2005, 03:00 PM
What info do you want displayed?

BigIke
03-24-2005, 09:49 PM
hey i got it all sorted out finally. Thanks for all the help, especially from Deaths and noppid.

actually, lol, i have one other thing... I got the title pulled, but how do i make it a link to that post? and the cut off is at 150 words, but how do i create a link that says "read more", for my users to read the rest of the posts?

Deaths
03-25-2005, 02:27 PM
Link to thread:
<a href="showthread.php?t=$box_forumid_1thread[threadid]">$box_forumid_1thread[title]</a>.

To limit the message to a certain amount of chars (in this case 250):

if (strlen(YOUR_VAR_FOR_MESSAGE) > '250')
{
YOUR_VAR_FOR_MESSAGE = fetch_trimmed_title(YOUR_VAR_FOR_MESSAGE, '250' . construct_phrase($vbphrase['read_more'], $vboptions['bburl'], $box_forumid_1thread['threadid'], $session['sessionurl']);
}

Don't forget to replace the YOUR_VAR_FOR_MESSAGE text with the variable you use for your message!
The PHP code must be added to the PHP file, BELOW the query, and BELOW the parsing of the bbcode in it (if you parse it), but ABOVE the calling for the template.

That should work, if not, let me know.

BigIke
03-26-2005, 03:50 PM
The link to the thread worked great. I'm not sure what you mean by the variable I use for my message, though..

Deaths
03-26-2005, 03:57 PM
Well, how do you display that text?

BigIke
03-26-2005, 04:13 PM
Do you mean the $box_forumid_1_first_post[pagetext]? I'm sorry, I'm in the process of learning PHP, but I'm not too far along.

Deaths
03-26-2005, 04:53 PM
Yes, that's it.

This should work:

if (strlen($box_forumid_1_first_post[pagetext]) > '250')
{
$box_forumid_1_first_post[pagetext] = fetch_trimmed_title($box_forumid_1_first_post[pagetext], '250' . construct_phrase($vbphrase['read_more'], $vboptions['bburl'], $box_forumid_1thread['threadid'], $session['sessionurl']);
}

BigIke
03-26-2005, 05:19 PM
I get this error:Parse error: parse error, unexpected ';' in /homepages/24/d116946458/htdocs/vb/modules/features.php on line 55
It's probably because I put it in the wrong place, but I checked and I think I put it where it should be. BTW thanks for coming back and checking my progress

Deaths
03-26-2005, 06:18 PM
Ah, sorry, my bad.

Its supposed to be this:


if (strlen($box_forumid_1_first_post[pagetext]) > '250')
{
$box_forumid_1_first_post[pagetext] = fetch_trimmed_title($box_forumid_1_first_post[pagetext], '250') . construct_phrase($vbphrase['read_more'], $vboptions['bburl'], $box_forumid_1thread['threadid'], $session['sessionurl']);
}

And if that doesnt work, you can try this aswell:


if (strlen($box_forumid_1_first_post['pagetext']) > '250')
{
$box_forumid_1_first_post['pagetext'] = fetch_trimmed_title($box_forumid_1_first_post['pagetext'], '250') . construct_phrase($vbphrase['read_more'], $vboptions['bburl'], $box_forumid_1thread['threadid'], $session['sessionurl']);
}

BigIke
03-26-2005, 06:32 PM
I tried both, but a "read more" doesn't show up. Check it out here (http://thevikesrike.tk). Should something be added to the template?

Deaths
03-26-2005, 06:36 PM
It should show up normally...

Try searching in your phrases for read_more, does that exist?

BigIke
03-26-2005, 06:42 PM
GOT IT! I took out the previous code that limited the post length because it was conflicting with your code, which worked. Thanks so much man for all your help; before all of this I was going to pay someone to do this for me, so you saved me some money. Again, thanks for the time you've put into this, and thanks to others who contributed.

Deaths
03-26-2005, 06:50 PM
No problem mate.

If you need any other help, just PM me, or post a thread :)