View Full Version : trouble with forumdisplay.php
jsell
10-23-2002, 03:00 AM
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
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
$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:
$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:
$threads=$DB_site->query("SELECT * FROM thread WHERE ...
to use a join query you have to chang it into this:
$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:
$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 :)
Chris M
10-23-2002, 10:08 PM
How would I make a Query to pull just the ReplyCount, The Thread Title, and then link it to the thread id?
Ive tried loads of queries, but i cant get it to work...
Could those queries be adapted?
If so, would you mind telling how?
Satan
NTLDR
10-23-2002, 10:35 PM
$threadquery=$DB_site->query("SELECT threadid,title,replycount FROM thread");
Then use $threadquery[threadid] for the threadid. The above query will return the values for all threads.
Chris M
10-23-2002, 10:37 PM
Cool thanks:)
You wouldnt happen to know how I could get that to display in a table would you?
Satan
NTLDR
10-23-2002, 10:42 PM
Basicly have this PHP and then two templates, the bit, for each result and the mainone to house them all:
$threadquery=$DB_site->query("SELECT threadid,title,replycount FROM thread");
while ($threadinfo = $DB_site->fetch_array($threadquery)) {
$title = unhtmlspecialchars($threadinfo['title']);
$replycount = $threadinfo['replycount'];
$threadid = $threadinfo['threadid'];
eval("\$threadbits .= \"".gettemplate('query_bit')."\";");
}
eval("\$threads = \"".gettemplate('query')."\";");
Change query_bit and query in the eval statements to your template names ;)
Chris M
10-23-2002, 10:47 PM
Thanks:)
Satan
jsell
10-23-2002, 11:08 PM
it doesn't work right i'm sure i'm doing something wrong
here is what i changed the $threads Query to
$threads=$DB_site->query("
SELECT $dotuserid $votequery ".iif($foruminfo[allowicons],'icon.title as icontitle,icon.iconpath,','')."
thread.threadid,thread.title,lastpost, forumid,pollid,open,replycount,postusername,postus erid,
lastposter,thread.dateline,views,thread.iconid,not es,thread.visible,sticky,votetotal,attach,reqdata. threadid,reqdata.filler AS reqfiller
FROM thread
LEFT JOIN reqdata USING (threadid)
".iif($foruminfo[allowicons],'LEFT JOIN icon ON (icon.iconid = thread.iconid)','')."
$dotjoin
WHERE $threadids
ORDER BY sticky DESC, $sortfield $sqlsortorder
");
then below inside the while loop
while ($thread=$DB_site->fetch_array($threads)) { // and $counter++<$perpage) {
i put
//request hack
if ($threads[reqfiller]!='') {
eval("\$filledby = \"".gettemplate('filledby')."\";");
} else {
$filledby='';
}
//request hack
but it doesn't assign a value to the variable $threads[reqfiller]
any idea
Thanks
--jsell
Chris M
10-23-2002, 11:13 PM
Thats because it would be :
//request hack
if ($thread[reqfiller]!='') {
eval("\$filledby = \"".gettemplate('filledby')."\";");
} else {
$filledby='';
}
//request hack
You assigned the variable $thread to fetch the array of $threads, so you use $thread not $threads;)
Try that code, and $thread[reqfiller];)
Satan
jsell
10-23-2002, 11:17 PM
Thanks i think my brain is fried
--jsell
Erwin
10-24-2002, 04:41 AM
LOL! I see that you're getting support from the pros here. :) Sorry I didn't get back to this thread sooner, but it looks like things are under control.
Xenon
10-24-2002, 09:03 AM
:)
you're welcome jsell
@Erwin: That thread is a good example:
So sees a problem and many users jump to it and try to solve ;)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.