I’m using this MySQL query, called by MySQL:
SELECT tf_posts.*, tf_threads.thread_id FROM tf_threads LEFT JOIN tf_posts ON tf_threads.thread_id=54
When I use mysql_fetch_array I get an array full of each field, but the actual values for the fields are acting very strangely indeed…
Any numeric or date fields are returned just fine; I can use them in the array. Any text fields, however, are empty. The array returned is shown below in it’s raw form:
Array
(
[0] =>
[id] =>
[1] =>
[thread_id] => 820515612
[2] =>
[poster_id] =>
[3] =>
[title] =>
[4] =>
[body] =>
[5] =>
[date] =>
[6] =>
[edit_date] =>
[7] =>
[edited] =>
[8] =>
[draft] =>
[9] =>
[spam] =>
[10] => 820515612
)
Ignore the numerical indexes here – I’m interested in the named ones. The fields body and title are text fields (CHAR()), and are, obviously, not displaying when they should be.
What have I done wrong or missed here? Is it because I’m using CHAR()? I strongly doubt it but I’m not great with MySQL.
EDIT:
The idea of this query is to select all threads from one table (tf_threads), and take the first post under that thread from another table (tf_posts) and use the posts title field as the title for the thread.
Thanks,
James
Your join clause doesn’t make sense to me. It looks like you’re trying to get all posts for thread_id 54, but you’re not joining the two tables, and you’re not getting any data from the tf_threads table other than thread_id, which I presume is also present in your tf_posts table. Why not just use a WHERE clause:
If this doesn’t work, please post your table descriptions and what the query should return.
To answer your edit, you need to actually join the tables then, and with an INNER JOIN if you only want one post – a LEFT JOIN would give you all posts for each thread.
This should give you all threads and the first post (as determined by the date column) for each thread.