Minimizing MySQL queries for forum thread index idea

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Minimizing MySQL queries for forum thread index idea

Post by JAB Creations »

Here is what I have and the output I get...this still looks a little odd?

Code: Select all

$result4 = mysql_query("SELECT ua.user_username AS author_username, ua.user_username_base AS author_username_base, ua_last.user_username AS last_username, ua_last.user_username_base AS last_username_base, ft.forum_thread_id, ft.forum_thread_count_posts, ft.forum_thread_count_replies, ft.forum_thread_count_views, ft.forum_thread_name FROM forum_threads AS ft LEFT JOIN user_accounts AS ua ON ft.forum_thread_author_id = ua.user_id LEFT JOIN user_accounts AS ua_last ON ft.forum_thread_author_id_last = ua_last.user_id WHERE forum_thread_forum_id='".$forum_id."' LIMIT 0 , 30");
$row4 = mysql_fetch_array($result4);
 
echo '<pre>';
var_dump($row4);
echo '</pre>';
array(18) {
[0]=>
string(13) "JAB Creations"
["author_username"]=>
string(13) "JAB Creations"
[1]=>
string(12) "jabcreations"
["author_username_base"]=>
string(12) "jabcreations"
[2]=>
string(9) "webmaster"
["last_username"]=>
string(9) "webmaster"
[3]=>
string(9) "webmaster"
["last_username_base"]=>
string(9) "webmaster"
[4]=>
string(1) "1"
["forum_thread_id"]=>
string(1) "1"
[5]=>
string(1) "1"
["forum_thread_count_posts"]=>
string(1) "1"
[6]=>
string(1) "0"
["forum_thread_count_replies"]=>
string(1) "0"
[7]=>
string(2) "12"
["forum_thread_count_views"]=>
string(2) "12"
[8]=>
string(18) "First Test Thread!"
["forum_thread_name"]=>
string(18) "First Test Thread!"
}
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Minimizing MySQL queries for forum thread index idea

Post by Eran »

Use mysql_fetch_assoc() instead
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Minimizing MySQL queries for forum thread index idea

Post by JAB Creations »

Arrays aren't a strength though I've been getting a lot of practice with them of late. :mrgreen:

Ok yeah I see the difference here much more clearly. Thanks for bringing that to my attention!
array(9) {
["author_username"]=>
string(13) "JAB Creations"
["author_username_base"]=>
string(12) "jabcreations"
["last_username"]=>
string(9) "webmaster"
["last_username_base"]=>
string(9) "webmaster"
["forum_thread_id"]=>
string(1) "1"
["forum_thread_count_posts"]=>
string(1) "1"
["forum_thread_count_replies"]=>
string(1) "0"
["forum_thread_count_views"]=>
string(2) "12"
["forum_thread_name"]=>
string(18) "First Test Thread!"
}
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Minimizing MySQL queries for forum thread index idea

Post by josh »

I prefer mysql_fetch_object()
Post Reply