vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Getting from plugin to forumhome .. ? (https://vborg.vbsupport.ru/showthread.php?t=167609)

steadicamop 01-12-2008 05:16 PM

Getting from plugin to forumhome .. ?
 
Hey all,

I've embarked on a small mod to one I already have installed - to show the number of new adverts in a section (it's not a forum and not visible from the forumhome) - so I've done the mysql queries to get what I need.

The next biggest problem is, how do I get these into a template, then somewhere near the bottom of the forumhome template.

I thought this was easier than I thought - but it would appear it's quite tricky!

TIA

Jason

Opserty 01-12-2008 05:18 PM

Assign the data you want to display to a variable then use that variable in your template.

steadicamop 01-12-2008 05:25 PM

I'm a little lost, it's so much different to what I'm used to, here is the code I have (it is messy but this meant it worked)

PHP Code:

$result = mysql_query("SELECT vbfclassifieds_ads.title, vbfclassifieds_ads.userid, vbfclassifieds_ads.id, user.userid, user.username FROM vbfclassifieds_ads LEFT JOIN user ON vbfclassifieds_ads.userid = user.userid LIMIT 5");

?><table border='0'>
<tr>
<th>Title</th>
<th>Username</th>
</tr>
<?php
while($row mysql_fetch_array($result))
  {
  
?>
<tr>
<td><a href=vbfclassifieds.php?do=showad&adid=<?php echo $row['id']; ?>><?php echo $row['title']; ?></a></td>  <td><a href=/member.php?u=<?php echo $row['userid']; ?>><?php echo $row['username']; ?></a></td>
</tr> <?php
  
}

How would I go around removing the table stuff and turning them into variables - then how do I use the while to just show 5 lines within that template?

Opserty 01-12-2008 08:59 PM

You need to assign out to variables, so if you have:
PHP Code:

// Some PHP code here
?>
<p>Some HTML here</p>
<?php
// Some more PHP Code
?>
<p>Some more HTML here</p>

You would change it to:
PHP Code:

// Some PHP Code
$somevar '<p>Some HTML code</p>';
// Some more PHP Code
$somevar .= '<p>Some more HTML code</p>'

(Don't for get that echo()'ing also outputs so you will to add that to the output. Note also how the period on the second assignment adds data to the end of variable.)

steadicamop 01-12-2008 09:10 PM

Thanks - I'm still very hazy on this, done a lot of searching and I'm still really none the wiser.

The way I've visualised this now is that the database queries are pulled and put into a variable (ie - $ads_id = $row->id; - which should pull from the row 'id' then put that into the variable $ads_id) or this is how I've interpreted it to be, then the $ads_id can be reused in the template.

If I've done this wrong please correct me - I'm a little unsure about the code you showed above, it makes some sense, but I have no idea where I would put the database query results.

Basically - I need these variables to achieve what I need:

$row['id']; - this is the id of the item
$row['title']; - this is the title of the item
$row['userid']; - this is the userid from the table, which is left joined to the user table, so that the username can be pulled
$row['username']; - this is from the user table, so that the username can be output rather than the userid

I hope this makes some sense, I'm just lost in translation between php and vbulletin!

Thanks for your help,

Jason

Opserty 01-12-2008 10:23 PM

I was trying to avoid doing it for you but maybe you will learn more from seeing how it should be.

PHP Code:

$result $db->query_read("SELECT vbfclassifieds_ads.title, vbfclassifieds_ads.userid, vbfclassifieds_ads.id, user.userid, user.username FROM vbfclassifieds_ads LEFT JOIN user ON vbfclassifieds_ads.userid = user.userid LIMIT 5");

$displaydata '
        <table border="0">
            <tr>
                <th>Title</th>
                <th>Username</th>
            </tr>
        '
;
while(
$row $db->fetch_array($result))
{
    
$displaydata .= '
            <tr>
                <td>
                    <a href="vbfclassifieds.php?do=showad&adid='
$row['id'] .'">
                        '
$row['title'] .'
                    </a>
                </td>  
                <td>
                    <a href="/member.php?u='
$row['userid'] .'">
                        '
$row['username'] .'
                    </a>
                </td>
            </tr>
            '

  }
$displaydata .= '</table>'

Then use $displaydata in your template.

steadicamop 01-13-2008 08:48 AM

Thanks - I thought from what you said it was easier to turn the query results into variables then use those in a template - I didn't really know if that was the easiest way of doing it, in all honesty, what I did looked untidy so I didn't want to use it.

My total aim is to have this on the forumhome - in or around the what's going on box - so it blends in seamlessly - that is the next step but I think that should be fairly simple to achieve with some searching.

Would what I posted above work - putting the queries into variables then passing those to a template?

Thanks for your assistance, I appreciate it.

Jason

Opserty 01-13-2008 09:00 AM

What I would have done is make use of two different templates so you would have:

forumhome_ads:
Code:

<table border="0">
        <tr>
                <th>Title</th>
                <th>Username</th>
        </tr>
        $adsbits
</table>

and forumhome_ads_bits:
Code:

        <tr>
                <td>
                        <a href="vbfclassifieds.php?do=showad&adid=$row[id]">
                                $row[title]
                        </a>
                </td> 
                <td>
                    <a href="/member.php?u=$row[userid]">
                        $row[username]
                    </a>
                </td>
            </tr>

Then your PHP:
PHP Code:

$result $db->query_read("SELECT vbfclassifieds_ads.title, vbfclassifieds_ads.userid, vbfclassifieds_ads.id, user.userid, user.username FROM vbfclassifieds_ads LEFT JOIN user ON vbfclassifieds_ads.userid = user.userid LIMIT 5");
$adsbits '';
while(
$row $db->fetch_array($result))
{
    eval(
'$adsbits .= "'fetch_template('forumhome_ads_bits') .'";');
}
eval(
'$displaydata = "'fetch_template('forumhome_ads') .'";'); 


steadicamop 01-13-2008 09:54 AM

Thanks - I'm following more clearly now, I will go with this system as it seems much simpler - and as well I can use existing template code to make it match in with the forumhome template, that's then my final problem, how would I go about adding it to the forumhome template - I just used the $displaydata variable and it showed up perfectly, but I'm unclear on how to get another template to show inside the forumhome template ... now I'm confusing things!

Thanks for all your help,

Jason

Opserty 01-13-2008 10:04 AM

I don't understand what your problem is with $displaydata. You just need to use it in your forumhome template thats all. (It contains both the other templates within it. So when you put it in your forumhome template they will show up)

You may find this useful: Create your own vBulletin tables

steadicamop 01-13-2008 10:13 AM

Aaaaaaah!! Now I understand - thank you, that's the one thing I overlooked, I didn't think that still applied - sorry to be so dumb on this, I'm still relatively new with getting inside vbb -- will work with all of this and get it sorted.

Thanks once again and I'm sorry for being so dumb :)

Jason

Opserty 01-13-2008 10:26 AM

We were all "n00bs" once. ;)


All times are GMT. The time now is 06:56 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01962 seconds
  • Memory Usage 1,766KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (12)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete