View Single Post
  #760  
Old 10-07-2007, 08:30 AM
TigerWare TigerWare is offline
 
Join Date: Feb 2007
Location: England, UK
Posts: 282
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by da prez View Post
does anyone have some created web queries they wouldn't mind sharing ?

thanks
Maybe there should be a repository somewhere?

Here is one that I have implemented which appears at the bottom of an article page written in LWT. The idea is to provide readers with snippets of comments made about the page they have just read, plus a visible link to a specific thread in the forum to read fully or add comments of their own. It displays a collapsable table containing the last 3 comments to the specific thread specified in the query. Text from each post is truncated at 500 characters. If there are no replies to the specified threadid, then the table content reverts to a generic "Be the first to add a comment" style.

Quote:
Query name: $WQ_comments_sometitle
Advanced Query?: Yes
Description: Displays information about comments for this page.

Query: (Required ThreadID is hard-coded in the WHERE clause)
Code:
select thr.threadid AS threadid, pst.title AS title, thr.firstpostid AS firstpostid, thr.replycount AS replycount, thr.views AS views, pst.postid AS postid, usr.username AS username, pst.dateline AS dateline, pst.userid AS userid, LEFT(pst.pagetext, 500) AS pagetext FROM thread AS thr LEFT JOIN post AS pst ON(thr.threadid = pst.threadid) LEFT JOIN user AS usr ON(usr.userid = pst.userid) WHERE thr.threadid = 0000 AND pst.postid <> thr.firstpostid  ORDER BY pst.postid DESC LIMIT 3
Query PHPInclude Code (Before): (Required ThreadID is hard-coded in the WHERE clause)
PHP Code:
$queryfirstpostid $db->query_first("SELECT firstpostid FROM " TABLE_PREFIX "thread AS thread WHERE threadid = 0000");
$firstpostid $queryfirstpostid[firstpostid]; 
The above PHPInclude provides the WebQuery with a variable [$firstpostid], which contains the first post id of the required thread. This variable is consumed in the 'Query No Results Row' which forms part of the link to the thread reply editor screen. (Many thanks to Logican for input on this).

Result Prefix Code:
HTML Code:
<div style="padding-bottom:15px">
  <table align="center" border="0" cellpadding="6" cellspacing="1" class="tborder" width="75%">
    <thead>
      <tr><td class="tcat"><a href="#top" onclick="return toggle_collapse('mysite_comments_module')" style="float:right"><img alt="" border="0" id="collapseimg_mysite_comments_module" src="images/buttons/collapse_tcat.gif" /></a>
      <span class="smallfont"><strong>&raquo; Discussion &amp; Comments...</strong></span></td></tr>
    </thead>
    <tbody id="collapseobj_mysite_comments_module" style="">
Query Result Row:
HTML Code:
<tr><td><span class="smallfont">&nbsp;</span></td></tr>
      <tr>
        <td class="thead"><a href="showthread.php?t=$WQfield[threadid]" title="[click here to view other comments]" target="_blank">$WQfield[title]</a></td>
      </tr>
      <tr>
        <td class="alt2">
          <div class="smallfont"><strong>Posted By</strong>:&nbsp;<span style="cursor:pointer" onclick="window.open('member.php?u=$WQfield[userid]')">$WQfield[username]</span></div>
          <div class="smallfont"><strong>Posted On</strong>:&nbsp;$WQfield[dateline]</div>
          <br/>
          <table align="center" border="0" cellpadding="6" cellspacing="1" class="tborder" width="95%">
            <tr>
              <td class="alt1">
                $WQfield[pagetext]<span class="smallfont"><a href="showthread.php?p=$WQfield[postid]#post$WQfield[postid]" title="[click here to read more]" target="_blank">...</a></span>
              </td>
            </tr>
          </table>
          <br/>
        </td>
      </tr>
      <tr class="thead"><td><span class="smallfont">Views ($WQfield[views]) - Comments ($WQfield[replycount]) - <a href="showthread.php?t=$WQfield[threadid]" title="[click here to view other comments]" target="_blank">View</a> or <a href="newreply.php?do=newreply&noquote=1&p=$WQfield[firstpostid]" target="_blank" title="[click here to add your comment now]">Add</a> Comments</span></td></tr>
Result Affix Code:
HTML Code:
</tbody>
  </table>
</div>
Query No Result Row:
HTML Code:
<tr><td class="alt2"><span class="smallfont">Be the first to <a href="newreply.php?do=newreply&noquote=1&p=$firstpostid" target="_blank" title="[click here to add your comment now]">Add</a> a comment.</span></td></tr>
BB Code Parsed Field Names: pagetext (can be omitted if your template is 'text parsed')
Date Parsed Field Names: dateline

[Note: If your template is 'text parsed' please ensure that the HTML shown above contains NO line breaks. This would be interpreted and a hard break added to each line with a <br/> HTML code. This will make the formatting look very strange]
** edit - see below **
The only caveat in the above configuration is the hard-coded id in the Query No Result Row. This is required because the LWT does not parse field result values in anything other than the Query Result Row. If the LWT could parse field values in Result Prefix Code, Result Affix Code and Query No Result Row, it would be utterly fantastic!

@Logican, is my above enhancement suggestion something that you may be planning for a furture version?


** Update **
Text in grey (above) is no longer relevant due to Logican's input. The example has now been enhanced to incorporate suggested php pre-query. Thanks Logican!

Anyway, I hope this gives an idea of what can be done. I am really just starting to learn certain aspects of the LWT, and it helps in learning mySQL syntax too, which is a plus! LWT rocks! :up:
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01494 seconds
  • Memory Usage 1,818KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (4)bbcode_html
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete