vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   trouble with forumdisplay.php (https://vborg.vbsupport.ru/showthread.php?t=44882)

jsell 10-23-2002 03:00 AM

trouble with forumdisplay.php
 
I hope someone can help me. I am trying to to figure out a way to pull a variable from a table seoperate from the threads table and have a value show in the forumdisplaybit. I try to place a query right after this code in forumdisplay.php

PHP Code:

while ($thread=$DB_site->fetch_array($threads)) { // and $counter++<$perpage) { 


but it doesn't seem to get the info from the DB is there i think i am placing this code incorrectly hope i explained this well enough
and that someone can help me

Thnaks in advance

jsell

Erwin 10-23-2002 03:02 AM

What is the variable and how are you writing the query line? Post exactly what you put down and where in forumdisplay.

jsell 10-23-2002 03:43 AM

the query i used is


PHP Code:

$reqdata=$DB_site->query_first("SELECT * from reqdata WHERE threadid=$threadinfo[threadid]"); 


this should return a variable i want to return is $reqdata[status]
a 1 or 0 to signify a yes or no which will the each open there own template to place into the forumdisplaybit and appear on nt appear based on the variable (i think that makes sense....lol) but i get novalue at all for any variable eventhough the data is there in the database

--jsell

Xenon 10-23-2002 02:20 PM

you know it's not good to have a query within a whileloop?

you should use a join-query instead.

nevertheless i think your where clause is wrong use this:
PHP Code:

$reqdata=$DB_site->query_first("SELECT * from reqdata WHERE threadid=$thread[threadid]"); 

$threadinfo isn't defined as i know ;)

jsell 10-23-2002 09:16 PM

well I fixed the problem with the variable, but now you have me intrigued as i am aparently not doing the correct way. If someone would kindly expalin to me how the join-Query Xenon is refering to should work I would like to know.

Thanks in advance

--jsell

Xenon 10-23-2002 09:21 PM

well, somewhere in your script you define the $threads variable:

Code:

$threads=$DB_site->query("SELECT * FROM thread WHERE ...
to use a join query you have to chang it into this:
Code:

$threads=$DB_site->query("SELECT thread.*,reqdata.* FROM thread LEFT JOIN reqdata USING(threadid) WHERE ...
then you don't need the query in th while loop anymore, you can acces to all data within reqdata table throug $thread variable :)

jsell 10-23-2002 09:28 PM

Thanks Again Xenon!!

A quick reply too :). it's not an issue in this particular case but for future reference I can see how this could cause one problem though if there are identically named fields in the two different tables then there would be a conflict is there a way around this??

--jsell

Xenon 10-23-2002 09:40 PM

you're welcome :)

if you have fields with identical names you shouldn't use the * use explicit names instead:

Code:

$threads=$DB_site->query("SELECT thread.threadid, thread.title,reqdata.title AS reqtitle FROM thread LEFT JOIN reqdata USING(threadid) WHERE ...
as you can see, the field title in table reqdata can be accesed throug $thread[reqtitle].

you can use the AS operator whenever you have two fields with same names to rename on of them

jsell 10-23-2002 09:42 PM

I See Now!! Thank you again for all you help

--jsell

Xenon 10-23-2002 09:44 PM

welcome :)

that's why i'm here.

if you have other questions, feel free to post, there are many people out which can help :)


All times are GMT. The time now is 06:49 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.00974 seconds
  • Memory Usage 1,735KB
  • 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
  • (3)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete