I'm trying to do two queries, does this code look right? bchocitation is a table that holds information about citations we are using. Ultimately I want a list of all citations that are not linked to. My plan was to get the list of citation titles, and compare them against titles in pagelinks, if the title does not appear in pagelinks then it isn't linked to.
//SELECT page_title FROM bchocitation, page WHERE bchocitation.page_id=page.page_id; $results = array(); $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->select( array( 'bchocitation', 'page'), //from 'page_title', //select array('bchocitation.page_id'=>'page.page_id'),//where __METHOD__, array() //extras ); while ($obj = $dbr->fetchObject($res)) { $results[] = $obj; } $dbr->freeResult($res); //SELECT pl_title FROM pagelinks WHERE pl_title='$title'; $result = ""; $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->select( 'pagelinks', //from 'pl_title', //select array('pl_title'=>"'$title'"),//where __METHOD__, array() //extras ); while ($obj = $dbr->fetchObject($res)) { $result = $obj; } $dbr->freeResult($res);
Any help is much appreciated! -Courtney Christensen
I don't know about the code itself, but there are some things that could be cleaned up. It would probably be best to use "list( $bchocitation, $page ) = $dbr->tableNamesN( 'bchocitation', 'page' );" to get the actual table names and put them in. That's for your use of "array('bchocitation.page_id'=>'page.page_id'),//where" because if you don't then if someone uses a prefix like mw_ then your extension will break because the table name will actually be mw_bchocitation but your script won't compensate for that. Next, just a little cleanup but... You don't need the extra array() at the end of those selects... I don't know where each of these are, but if they are in the same area you can do without calling wfGetDB twice... Also, you're only selecting the page_title/pl_title, so wouldn't it be a good idea to actually pull that out of the object and put it into the results as a single string instead of putting an object with only a string there that doesn't have a consistent key. You're also using a while, and not using a selectRow or a LIMIT 1 when your assigning things not to an array, but a single variable which will only take one of the results.
~Daniel Friesen(Dantman) of The Gaiapedia, Wikia Graphical Entertainment Project, and Wiki-Tools.com
Christensen, Courtney wrote:
I'm trying to do two queries, does this code look right? bchocitation is a table that holds information about citations we are using. Ultimately I want a list of all citations that are not linked to. My plan was to get the list of citation titles, and compare them against titles in pagelinks, if the title does not appear in pagelinks then it isn't linked to.
//SELECT page_title FROM bchocitation, page WHERE bchocitation.page_id=page.page_id; $results = array(); $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->select( array( 'bchocitation', 'page'), //from 'page_title', //select array('bchocitation.page_id'=>'page.page_id'),//where __METHOD__, array() //extras ); while ($obj = $dbr->fetchObject($res)) { $results[] = $obj; } $dbr->freeResult($res);
//SELECT pl_title FROM pagelinks WHERE pl_title='$title'; $result = ""; $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->select( 'pagelinks', //from 'pl_title', //select array('pl_title'=>"'$title'"),//where __METHOD__, array() //extras ); while ($obj = $dbr->fetchObject($res)) { $result = $obj; } $dbr->freeResult($res);
Any help is much appreciated! -Courtney Christensen
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org