play_ Posted December 19, 2011 Share Posted December 19, 2011 Not sure if what I am trying to do is possible. It's gonna be a bit hard to explain but it's actually simple. Ok so first off, here's what an example paste(it's a pastebin site): http://tabbit.org/9aEXPo http://tabbit.org/-pua What I need help with is the 'recent' link, where I would like to display the last 10 or so pastes. The complication arises with the fact the pastebin has 'tabs'. MySQL tables are set up as such. When you make a new paste, it's id gets created in the table 'ids' as 'paste_id'. Each tab in the paste gets inserted into 'pastes' table, and it connects to the 'ids' table via paste_id. So for the 'recent' page, I am trying to gather some of the latest pastes. Right now the recent just prints an array that the query returns. If you go there right now, you'll see Array ( [pastes] => Array ( [0] => Body of tab 1, paste 1 [1] => Body of tab 2, paste 1 [2] => Body of tab1, paste 2 [3] => Body of tab2, paste 2 ) [tabs] => Array ( [0] => Tab1 [1] => Tab2 [2] => Tab1 [3] => Tab2 ) ) Ideally, I would want MySQL to return an array(paste_id) that contains 2 inner arrays - one holding the tab names, and the other holding the body of the paste array => [paste_id (1)] [tabs] [0] tab1 [1] tab2 [paste] [0] <?php .... ?> [1] <? php code or anything ?> [paste_id (2)] [tabs] [0] tab1 [1] tab2 [paste] [0] import twisted [1] from some.module import * is it possible? Quote Link to comment Share on other sites More sharing options...
fenway Posted December 20, 2011 Share Posted December 20, 2011 Show us your query. Quote Link to comment Share on other sites More sharing options...
play_ Posted December 22, 2011 Author Share Posted December 22, 2011 As of right now, there is none. I have tried all joins that I could. I am not too knowledgeable with complex queries, so i came here. One alternative is to use GROUP_CONCAT...but since it's for a pastebin site, i couldn't really risk using it since the separator could be in someone's paste where pastes.paste_id = $result['ids.paste_id'] <-- not syntax correct, but just to give the idea. alternative 2 is to run two queries. one to get the last 10 paste_id from 'ids'., and then for each id, do a select * from Quote Link to comment Share on other sites More sharing options...
fenway Posted December 22, 2011 Share Posted December 22, 2011 You may have none that you like, but you defintely have something. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.