Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2004, 12:20 PM
dontpanic dontpanic is offline
 
Join Date: Jun 2003
Posts: 145
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help in writing SQL query

EDIT: Now I would like to do this in vB 3.6 (last post).

I would like to have a bit of code in the showthread.php file and showthread template to accomplish the following task: I'd like to have different information shown in the header depending on what forumid is being viewed. I've currently accomplished this in vB 3.x using <if> conditionals in the showthread tempalte, but this is making the showthread template VERY long and I've seen a few random errors since I've implemented it that I think may be attributable to the length of the showthread template.

What I'd rather do is have the query pull the results of the DB depending on what forumid is being shown and pass them into the template using a variable. I'm not sure how to write the query and such. I will only have two fields in the table, forumid and content. I'd like it such that if the forumid being viewed on the showthread.php page is equal to one that is in the table it shows that defined content. If there is no match, I'd like it such that the query returned some default row from the table.

If you're curious as to what I'm really trying to do, have a look at my forums. On this page, you can see the header information (which is inserted by the showthread template) has information on books for the 70-292 exam:
http://www.mcseworld.com/forums/showthread.php?t=12495

On this one, it has information on books for the 70-296 exam:
http://www.mcseworld.com/forums/showthread.php?t=12522

And so forth. Like I mentioned previously, this is currently being done by a rather large chunk of HTML with conditionals in the showthread template. Here is an example of that for one of the forums:
PHP Code:
<!-- 70-292 -->
<if 
condition="$foruminfo['forumid']==114">

<
div align="center">
  <
center>

<
table class="tborder" cellpadding="0" cellspacing="$stylevar[cellspacing]border="0" width="100%" style="border-collapse: collapse" bordercolor="#111111">

<
tbody>
    <
tr>
        <
td class="thead" colspan="5" width="100%" align="left" valign="top">
            <
a style="float:$stylevar[right]href="#top" onclick="return toggle_collapse('forumhome_poparticles')"><img id="collapseimg_forumhome_poparticles" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_poparticles].gif" alt="" border="0" /></a>MCSE 
            World Recommended Reading
</td>
    </
tr>
</
tbody>
<
tbody id="collapseobj_forumhome_poparticles" style="$vbcollapse[collapseobj_forumhome_poparticles]">
    <
tr>
        <
td class="alt1Active" width="100%" align="left" valign="top" colspan="5">
        <
span class="smallfont"><b>Exam 70-292:&nbspManaging and Maintaining a 
        Microsoft Windows Server 2003 Environment 
for an MCSA Certified on 
        Windows 2000.
&nbsp;&nbsp; </b></span></td>
    </
tr>
        <
tr>
        <
td class="alt1Active" width="20%" align="center" valign="top">
        <
a href="http://www.mcseworld.com/a/1932266569" target="_blank">
        <
IMG SRC="http://images.amazon.com/images/P/1932266569.01.MZZZZZZZ.jpg" width="111" height="140" border="0"></a></td>
        <
td class="alt1Active" width="20%" align="center" valign="top">
        <
a href="http://www.mcseworld.com/a/0789729466" target="_blank">
        <
img border="0" src="http://images.amazon.com/images/P/0789729466.01.MZZZZZZZ.jpg" width="93" height="140"></a></td>
        <
td class="alt1Active" width="20%" align="center" valign="top">
        <
a href="http://www.mcseworld.com/a/0782142672" target="_blank">
        <
img border="0" src="http://images.amazon.com/images/P/0782142672.01.MZZZZZZZ.jpg" width="116" height="140"></a></td>
        <
td class="alt1Active" width="20%" align="center" valign="top">
        <
a href="http://www.mcseworld.com/a/0735619719" target="_blank">
        <
img border="0" src="http://a1055.g.akamai.net/f/1055/1401/5h/images.barnesandnoble.com/images/7040000/7042064.gif" width="100" height="132"></a></td>
        <
td class="alt1Active" width="20%" align="center" valign="top">
        <
a href="http://www.mcseworld.com/a/1932266615" target="_blank">
        <
img border="0" src="http://images.amazon.com/images/P/1932266615.01.MZZZZZZZ.jpg" width="111" height="140"></a></td>
        </
tr>
        <
tr>
        <
td class="alt1Active" width="100%" align="center" valign="top" colspan="5"><div class="smallfont">
        <
b>Please help support MCSE World by purchasing your study materials 
        through these links to Amazon
.com.</b></div></td>
    </
tr>
</
tbody>
</
table>
  </
center>
</
div>
<
br>
</if>
<!-- 
70-292 --> 
If pulling the information from the database, I'd obviously just have to code the table itself and the rest of the data would be in the DB and passed via the output variable of the SQL query.

Thanks in advance.
Reply With Quote
  #2  
Old 02-01-2004, 01:54 PM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

dontpanic,

Instead of making a new table and having to JOIN the table info I just added fields to the forum TABLE.

Queries To Run ( 3 )
If you have table prefixes don't forget to add it to the 'forum' in the sqls below.

Code:
ALTER TABLE forum ADD usedefbk TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0'
ALTER TABLE forum ADD bktitle VARCHAR ( 100 ) NOT NULL
ALTER TABLE forum ADD bkcontent MEDIUMTEXT NOT NULL
File Modifications ( 3 )
Note that I did not vb phrase the data below.

Open admincp/forum.php ( 3 )

Find: ( 1 )

PHP Code:
            'warnall' => 
Under It Add:

PHP Code:
            'usedefbk' => 
Find: ( 2 )

PHP Code:
    print_yes_no_row($vbphrase['show_forum_on_forum_jump'], 'options[showonforumjump]'$forum['showonforumjump']); 
Under It Add:

PHP Code:
    print_table_header "Forum Book Content Information" ) ;

    
print_yes_no_row "Use Default Book Info"'forum[usedefbk]'$forum['usedefbk'] ) ;
    
print_input_row "Book Title"'forum[bktitle]'$forum['bktitle'] ) ;
    
print_textarea_row "Book Content"'forum[bkcontent]'$forum['bkcontent'] ) ; 
Find: ( 3 )

PHP Code:
    $forum['description'] = convert_to_valid_html($forum['description']); 
Under It Add:

PHP Code:
    $forum['bktitle'] = convert_to_valid_html $forum['bktitle'] ) ;
    
$forum['bkcontent'] = convert_to_valid_html $forum['bkcontent'] ) ; 
Open SHOWTHREAD Template

Replace Your Code Of Conditionals Relating To Forumids With Something Similar To This:

Code:
<!-- book content -->
<div align="center">
  <center>

<table class="tborder" cellpadding="0" cellspacing="$stylevar[cellspacing]" border="0" width="100%" style="border-collapse: collapse" bordercolor="#111111">

<tbody>
	<tr>
		<td class="thead" colspan="5" width="100%" align="left" valign="top">
			<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_poparticles')"><img id="collapseimg_forumhome_poparticles" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_poparticles].gif" alt="" border="0" /></a>MCSE 
            World Recommended Reading</td>
	</tr>
</tbody>
<tbody id="collapseobj_forumhome_poparticles" style="$vbcollapse[collapseobj_forumhome_poparticles]">
    <tr>
        <td class="alt1Active" width="100%" align="left" valign="top" colspan="5">
        <span class="smallfont"><b>
		<if condition="$foruminfo['usedefbk']==1">
		$foruminfo[bktitle]
		<else />
		<!-- default book title goes here -->
		</if>
	  </b></span></td>
    </tr>
        <tr>
        <td class="alt1Active" width="20%" align="center" valign="top">
		<if condition="$foruminfo['usedefbk']==1">
		$foruminfo[bkcontent]
		<else />
		<!-- default book content goes here -->
		</if>
	  </td>
    	</tr>
        <tr>
        <td class="alt1Active" width="100%" align="center" valign="top" colspan="5"><div class="smallfont">
        <b>Please help support MCSE World by purchasing your study materials 
        through these links to Amazon.com.</b></div></td>
    </tr>
</tbody>
</table>
  </center>
</div>
<br>
<!-- book content -->
Cheers,
g-force2k2
Reply With Quote
  #3  
Old 02-01-2004, 02:24 PM
dontpanic dontpanic is offline
 
Join Date: Jun 2003
Posts: 145
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

g-force2k2,

Thanks. I will try it out later on my test forums and let you know how it went.
Reply With Quote
  #4  
Old 02-05-2004, 11:05 PM
dontpanic dontpanic is offline
 
Join Date: Jun 2003
Posts: 145
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, here's the final result.

IT WORKED!

I did make some minor mods:

My final template:
Code:
<!-- Book Content -->
<div align="center">
  <center>

<table class="tborder" cellpadding="0" cellspacing="$stylevar[cellspacing]" border="0" width="100%" style="border-collapse: collapse" bordercolor="#111111">

<tbody>
	<tr>
		<td class="thead" colspan="5" width="100%" align="left" valign="top">
			<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_poparticles')"><img id="collapseimg_forumhome_poparticles" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_poparticles].gif" alt="" border="0" /></a>MCSE 
            World Recommended Reading</td>
	</tr>
</tbody>
<tbody id="collapseobj_forumhome_poparticles" style="$vbcollapse[collapseobj_forumhome_poparticles]">

<if condition="$foruminfo['usedefbk']== 0">
$foruminfo[bkcontent]
<else />   
 
    <tr>
        <td class="alt1Active" width="100%" align="left" valign="top" colspan="5">
        <span class="smallfont"><b>Off the beaten path.</b></span></td>
    </tr>
    <tr>
        <td class="alt1Active" width="20%" align="center" valign="top">
        <a href="http://www.mcseworld.com/a/0321108957" target="_blank">
        <img border="0" src="http://images.amazon.com/images/P/0321108957.01.MZZZZZZZ.jpg" width="111" height="140"></a></td>
        <td class="alt1Active" width="20%" align="center" valign="top">
        <a href="http://www.mcseworld.com/a/0201746131" target="_blank">
        <img border="0" src="http://images.amazon.com/images/P/0201746131.01.MZZZZZZZ.jpg" width="110" height="140"></a></td>
        <td class="alt1Active" width="20%" align="center" valign="top">
        <a href="http://www.mcseworld.com/a/0471237124" target="_blank">
        <img border="0" src="http://images.amazon.com/images/P/0471237124.01.MZZZZZZZ.jpg" width="93" height="140"></a></td>
        <td class="alt1Active" width="20%" align="center" valign="top">
        <a href="http://www.mcseworld.com/a/0072229020" target="_blank">
        <img border="0" src="http://images.amazon.com/images/P/0072229020.01.MZZZZZZZ.jpg" width="113" height="140"></a></td>
        <td class="alt1Active" width="20%" align="center" valign="top">
        <a href="http://www.mcseworld.com/a/1931836884" target="_blank">
        <img border="0" src="http://images.amazon.com/images/P/1931836884.01.MZZZZZZZ.jpg" width="111" height="140"></a></td>
    </tr>
    	
</if>   
		 	
    <tr>
        <td class="alt1Active" width="100%" align="center" valign="top" colspan="5"><div class="smallfont">
        <b>Please help support MCSE World by purchasing your books through these links to Amazon.com.</b></div>
        </td>
    </tr>
</tbody>
</table>
</center>
</div>
<br>
<!-- Book Content -->
I did not use the
Code:
ALTER TABLE forum ADD bktitle VARCHAR ( 100 ) NOT NULL
database field, as I am coding that into the book content field. I also used this code in the admincp/forums.php:
Code:
print_table_header ( "Forum Book Content Information" ) ; 

    print_yes_no_row ( "Use Custom Book Info", 'forum[usedefbk]', $forum['usedefbk'] ) ; 
    print_textarea_row ( "Book Content", 'forum[bkcontent]', $forum['bkcontent'] ) ;
Thanks for your help! You can see it in action on any thread view at MCSE World.
Reply With Quote
  #5  
Old 08-26-2006, 05:58 PM
dontpanic dontpanic is offline
 
Join Date: Jun 2003
Posts: 145
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can anyone perhaps point me in the right direction to do this in vB 3.6? I've got the table modified, but I can't save changed in the AdminCP due ot the values not being defined in the class_dm.php file. As well, it looks like the conditionals are different now...at least that $foruminfo doesn't seem to be doing the trick anymore to get something on the showthread page.

Thanks.
Reply With Quote
Reply


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 03:36 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.06958 seconds
  • Memory Usage 2,273KB
  • Queries Executed 13 (?)
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
  • (5)bbcode_code
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete