vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Help with Tempplates & SQL Queries (https://vborg.vbsupport.ru/showthread.php?t=3486)

09-27-2000 01:07 AM

I'm writing a hack (ha! If you can even call it that - I'm not that talented)...and basically, I'd like to use SQL queries in the same format as vBulletin - since that seems to be the most logical thing to do...however, I can't get it to display more than one entry...any advice? I'll obviously need a while loop, but I'm not sure how to format it...

Here's what I have (which produces an error):

Code:

$query2=$DB_site->query_first("SELECT * FROM savethreads WHERE saveuser='$username'");
$result = mysql_query($query2,$DB_site);
while ($row = mysql_fetch_array($result)) {
        $savethreadid = $row["savethreadid"];
echo("$savethreadid");

Any thoughts?

Oh, also: I've created a custom template which is pulled onto a custom PHP page in my forums directory (thanks JimF! :D)...however the template displays first, with all my queries and their results below it all - how can I stick it in the middle of the template? I don't recall seeing actual queries used in any of the other templates...so I know there must be some other way.

Thanks! :)

09-27-2000 01:25 AM

Code:

$query2=$DB_site->query("SELECT * FROM savethreads WHERE saveuser='$username'");
while ($row = $DB_site->fetch_array($result)) {
        $savethreadid = $row["savethreadid"];
echo("$savethreadid");
}


09-27-2000 10:01 PM

Thanks Ed - very cool.

Anyone got any thoughts on the template problem? I'll bet the answer is simple - yet it escapes me somehow. :)

09-27-2000 10:07 PM

Uh...the other thing still doesn't work I'm afraid:

Warning: Supplied argument is not a valid MySQL result resource in /usr/home/webdev/mycoding/spunkyjunk.com/docs/testboard/admin/db_mysql.php on line 82

Using this code:

Code:

$query2=$DB_site->query("SELECT * FROM savethreads WHERE saveuser='$username'");
while ($row = $DB_site->fetch_array($result)) {
        $savethreadid = $row["savethreadid"];
echo("$savethreadid");
}


09-27-2000 10:28 PM

You need to replace $result with $query2

09-28-2000 12:11 AM

Oops, sorry 'bout that - thanks rangers.

09-28-2000 12:25 AM

Bingo! My mistake - still have a bit to learn about PHP's interaction with SQL (obviously) :)

Anyone else got the info on my template problem? It's one of the last hurdles in finishing the hack! :D

09-28-2000 10:51 AM

Hmmm...maybe I'll be forced to figure it out myself, hehe. :)

It's okay - I can handle it! I hope! :)

09-28-2000 01:56 PM

Post the code you have for your template.

09-28-2000 02:42 PM

Here's a new template I've created for one of the pages used in my hack:

Code:

{htmldoctype}
<HTML>
<HEAD><TITLE>$pagetitle</title>
$cssinclude
$headinsert
</head>
<body>
$header

<table border="0" width="100%"><tr>
<td valign="top" align="left"><a href="index.php"><img src="$titleimage" border="0"></a></td>

<td valign="middle" align="center" nowrap>
$fivelinks
</td></tr></table>

<table border=0 cellpadding=4 cellspacing=1 width=100%>
<tr bgcolor="{tableheadbgcolor}"><TD width="100%">

<normalfont color="{tableheadtextcolor}" class=thtcolor><B>vBulletin Message</B></normalfont>

</td></tr>
<tr bgcolor="{firstaltcolor}"><td width="100%">
WANT STUFF TO GO RIGHT HERE!</td></tr></table>

<p align="center">$forumjump</p>

$footer

</body>
</html>

Obviously I want to put all my SQL queries and echo statements right where "WANT STUFF TO GO RIGHT HERE!" is...but how can I do that in the template? For the other templates on the script I see variables in that spot...$errormessage, or the like. I have an idea of how to do this, but definetly need some help! :)

09-28-2000 02:59 PM

Well say we have the variable from your query above:

$savethreadid

You place [/b]$savethreadid[/b] in the template where you want that value to appear.

---

You just do this if your template doesn't contain other templates (like forumdisplay contains forumdisplaybit):

eval("echo dovars(\"".gettemplate("Your_Template_Name_Here"). "\");");

Example:

<?

// Your PHP code goes here, your queries
// $query = (...);
// $savethreadid = (...);
// $othervars = (...);
//
//eval("echo dovars(\"".gettemplate("Your_Template_Name_Here"). "\");");

If you place "$query" and "$savethreadid" and "$othervars" in your template than they will appear as you expect. What are you doing now? Did you place the call to the template before your queries and assignments?

[Edited by rangersfan on 09-28-2000 at 12:03 PM]

09-28-2000 04:04 PM

I see...you're right. I will call the variables later...the problem is, however, that I have a while loop in use - can I "call" the entire loop with a single variable?

09-28-2000 04:11 PM

So you have a while loop that will be outputting data to be displayed in the template?

You make a second template that would equal one line of the data. You then call that template at the end of the while loop. You need to look at the code to see what you need to do. Open search.php and see how the code uses "searhresultbit" as the template in a while loop. You will see the code assigns all the results of the while loop to one variable and then references that variable in the "searchresults" template.

09-29-2000 12:42 AM

Thanks man...used some of your advice, and worked around the rest.

Lo and behold: one of my last hurdles! :)

Code:

$DB_site->query("INSERT INTO savethreads (savethreadid,threadlinkid,saveuser) VALUES (NULL,$threadid,$username)");
I get the "Email has been dispatched to the Techial Guy" message because of this query - wazzup? I'm racking my brain over it...it looks fine to me.

09-29-2000 02:41 AM

Try this one ;)

Code:

$DB_site->query("INSERT INTO savethreads (savethreadid,threadlinkid,saveuser) VALUES (NULL,$threadid,'".addslashes($username)."')");
You actually only need to enclose $username in singlequotes as it a string but addslashes will make sure you don't get errors if it contains characters that need to be escaped.

09-29-2000 03:19 AM

Seems to have worked - thanks a bunch!

Yes, yet another question! :): How do I grab the variables (on a non-VB page) of whether or not the board makes use of hot topics, and the number of posts the board has used to set hot topics? I just need the SQL query basically, or the names of the fields and what table they're in. :)

Oh so close... :)

09-29-2000 04:17 AM

I'm not familiar with that setting or I am not understanding you.

09-29-2000 04:27 AM

Well, as you know, a post with 15 or more replies is designated as a "hot topic", and an "H" (or on some boards, a flame) is shown over the topics' folder.

The control panel allows you to disable this feature...it also allows you to determine how many replies a topic needs to become "hot"...I just need to know how I can call these values onto a non VB page... :)

09-29-2000 05:12 AM

Oh that, ok..

They are stored in the templates table in a template name options (along with all the other CP options"

$usehotthreads = "1";
$hotnumber = "15";

They will actually be available to you if you just access those variables since they are set in global.php and will flow to your script.

(if $hotthreads == "1" ) // yes
(if $hotthreads == "0") // No

09-29-2000 07:38 PM

Ok, thanks! Works just fine. You the man.

Thanks for your help...getting over these little hurdles has really helped me. Expect the hack shortly! :)

09-29-2000 07:45 PM

btw, what is this hack? :)

09-29-2000 08:27 PM

It's called the "Save Threads" hack :) That alone should explain it...hehe.

If I can just figure out one or two more things, it'll basically be ready for release!


All times are GMT. The time now is 02:19 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.01212 seconds
  • Memory Usage 1,758KB
  • 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
  • (6)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (22)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