PDA

View Full Version : Accessing field in first 'post' per thread


MacMorag
08-03-2004, 01:56 PM
You know how sometimes you look at a problem for so long that you begin to wonder what it is you're trying to do in the first place? Well, I'm there :ermm:

What I'm trying to do:

Every thread has an associated 'first' post. Correct.

I would like to access a specific field in this 'first' post, for a dynamic range of threadids, and be able to access the contents of this field.

e.g. Thread with 'threadid' of '123', has a first post whose 'postid' is '456'. This post (postid=456) has a field called 'sample' which contains "ABC".

I'd like to access the contents of 'sample' when I only have the 'threadid' as a reference point to start with.

So 'threadid' 100 returns "ABC".

What SQL statement do I need to use to get to this data? I know how to extract the first 'postid' for a thread. How do I then extract a specific field from the post?

Thanks for any help.

Natch
08-03-2004, 02:04 PM
How do you wanna access it ? in the postbit ? <if condition="$post[postcount] == 1">
<if condition="$post[sample]">$post[sample]</if>
</if>Will that do the trick ?

Colin F
08-03-2004, 02:05 PM
SELECT post.sample FROM thread LEFT JOIN post on thread.firstpostid = post.postid WHERE thread.threadid = $threadid


something like that should work, change if you have table prefixes.

MacMorag
08-03-2004, 02:10 PM
Hi Natch,

No, I want to access it from index.php

1. I have added a field to the post table called "sample", which is written to when the FIRST post is submitted.

2. I am displaying the latest 10 threads on index.php, and I would like to display the contents of "sample" for each.

Thanks, Morag.

Natch
08-03-2004, 02:12 PM
Colin F read your post and has it right :)

MacMorag
08-03-2004, 02:12 PM
Thanks Colin - that should do the trick.

Headache receding already :)