If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Is someone able to comment/verify this MySQL coding please? Out of my depth :/

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-14-11, 14:41
NeilF NeilF is offline
Registered User
 
Join Date: Apr 2011
Posts: 1
Is someone able to comment/verify this MySQL coding please? Out of my depth :/

I've got a PHP script which is doing two things (with a vBulletin database). Returning the most recent 10 posts from a dedicated forum (for a news feed). And returning the most recent 10 posts from a list of forums (for a current discussion feed).


Here's the two requests:-
News
Code:
     $NewestNews = $db->query("
            select t.*,p.pagetext
            from ".TABLE_PREFIX."thread t
            left join ".TABLE_PREFIX."post p on(p.postid=t.firstpostid)
            where t.forumid = $Forum
            order by dateline desc
            limit 0,$Amount");

    while($News = $db->fetch_array($NewestNews)){
        ...blah...
Current Discussion
Code:
    $NewestReplies = $db->query("select * from ".TABLE_PREFIX."thread where forumid in({$Forums}) order by lastpost desc limit 0,$Amount");

    while($Thread = $db->fetch_array($NewestReplies)){
        ...blah...
I know nothing about MySQL, so is anyone able to kindly confirm the above request are:-
a) Correct (they certainly seem to work).
b) Efficient. ie: They're not reading thousands of records to return 10 ($amount).



Secondly, and this for VBulletin aware folks, I notice the requests are returning:-
a) Soft deleted posts.
b) Redirected posts.

Would these changes (" and t.visible=1 and t.pollid=0") correctly skip/omit those (efficiently)?

News
Code:
     $NewestNews = $db->query("
            select t.*,p.pagetext
            from ".TABLE_PREFIX."thread t
            left join ".TABLE_PREFIX."post p on(p.postid=t.firstpostid)
            where t.forumid = $Forum and t.visible=1 and t.pollid=0
            order by dateline desc
            limit 0,$Amount");

    while($News = $db->fetch_array($NewestNews)){
        ...blah...
Current Discussion
Code:
    $NewestReplies = $db->query("select * from ".TABLE_PREFIX."thread  where forumid in({$Forums}) and visible=1 and pollid=0 order by lastpost desc limit 0,$Amount");

    while($Thread = $db->fetch_array($NewestReplies)){
        ...blah...
Thanks in advance for any/all help! I'm very out of my depth here!

My confusion is I especially don't understand why the syntax of the two requests vary so much. ie: Why one is talking to "t.*,p.pagetext" and the other is not!?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On