Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2008, 05:16 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 01-12-2008, 05:18 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Assign the data you want to display to a variable then use that variable in your template.
Reply With Quote
  #3  
Old 01-12-2008, 05:25 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #4  
Old 01-12-2008, 08:59 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.)
Reply With Quote
  #5  
Old 01-12-2008, 09:10 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 01-12-2008, 10:23 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 01-13-2008, 08:48 AM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #8  
Old 01-13-2008, 09:00 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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') .'";'); 
Reply With Quote
  #9  
Old 01-13-2008, 09:54 AM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 01-13-2008, 10:04 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:03 PM.


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.09572 seconds
  • Memory Usage 2,272KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete