m11oct Posted November 26, 2006 Share Posted November 26, 2006 I have a site which runs using the MediaWiki software.There is a script in the software which automatically selects a random page for the user to view.The code (contained in the file "SpecialRandompage.php") is:[code] $randstr = wfRandom(); $db =& wfGetDB( DB_SLAVE ); $use_index = $db->useIndexClause( 'page_random' ); $page = $db->tableName( 'page' ); $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : ''; $sql = "SELECT page_id,page_title FROM $page $use_index WHERE page_namespace=$namespace AND page_is_redirect=0 $extra AND page_random>$randstr ORDER BY page_random"; $sql = $db->limitResult($sql, 1, 0); $res = $db->query( $sql, $fname );[/code]My problem is that there are certain pages which I would like to exclude from being selected when a user wants to view a random page. The pages which I don't want to be selected randomly are "disambiguation" pages. The problem is that unlike "page_is_redirect", there is no "page_is_disambiguation" field in the database.In the wiki, all disambiguation pages are also categorised into a category called "Disambiguation". This results in them being listed in a different table of the database (tablename: categorylinks). In this table, "page_id" in the first table would match the value of "cl_from" in the categorylinks table. There may be more than one row with a matching "cl_from" value. If the page is a disambiguation, there would be a row where "cl_from" matched "page_id" and "cl_to" was equal to text string "Disambiguation".Any ideas how I would change the SQL query in the code? I am quite experienced with PHP but just need a little guidance on the SQL code.Thanks in advance,Michael Quote Link to comment https://forums.phpfreaks.com/topic/28482-query-problem-relating-to-wiki/ Share on other sites More sharing options...
fenway Posted November 26, 2006 Share Posted November 26, 2006 You'll have to left join in that categorylinks table and only return the records that don't match (i.e. IS NULL). Quote Link to comment https://forums.phpfreaks.com/topic/28482-query-problem-relating-to-wiki/#findComment-130482 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.