Jump to content


How To Make Etomite Do This Query?


  • You cannot reply to this topic
2 replies to this topic

#1 andrey_fisher

    Etomite Forum Newbie

  • Member
  • 12 posts

Posted 08 February 2006 - 01:24 AM

I've got more than one etomised sites. They all located on one server and share one database, so tables *prefix_site_content* have only one difference - the prefix.
All sites have NewsListingRevised snippet installed.

One site should grab some pages from another sites and show them like news by using NewsListingSnippet.
In another words, $resource array should contain the data taken from different tables.

I provide to ther $etomite -> dbQuery() function a query like this:

[code](SELECT id, pagetitle, description, content, createdon, createdby FROM main_site_content WHERE main_site_content.parent=8 AND main_site_content.published=1 AND main_site_content.deleted=0) UNION (SELECT id, pagetitle, description, content, createdon, createdby FROM nic_site_content WHERE nic_site_content.parent=8 AND nic_site_content.published=1 AND nic_site_content.deleted=0) ORDER BY createdon DESC[code]

but.. it returnes an error.

How to make Etomite (get ActiveChildren() function) work with this query?

Edited by andrey_fisher, 08 February 2006 - 01:28 AM.


#2 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 08 February 2006 - 02:58 AM

If you choose to use the dbQuery() API function you would need to create a variable that includes the database name and prefix for each sites prefix... For example, $tbl_1 = $tbl = $etomite->dbConfig['dbase'].".prefix_1; and $tbl_2 = $tbl = $etomite->dbConfig['dbase'].".prefix_2; which you could then use to access the same tables from different datasets using $tbl_1."site_content" and $tbl_2."site_content"...

That should get you headed inthe right direction... If you need additional help, just ask... B)

#3 andrey_fisher

    Etomite Forum Newbie

  • Member
  • 12 posts

Posted 09 February 2006 - 12:06 AM

thanks, Ralph, it works!

here's my code, that grabs the news from tho Eto sites sharing one database:

$this->dbs = array();
    $this->dbs[0] = $this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']; // this site DB prefix
    $this->dbs[1] = $this->dbConfig['dbase'].".".$this->dbConfig['table_prefix_nic']; // another site's DB prefix
  }

................

function getAllActiveChildren($id=0, $sort='menuindex', $dir='', $fields='id, pagetitle, longtitle, description, parent, alias, prefix') {

$sel=array();
for($a=0;$a<sizeof($this->dbs);$a++){
    $tbl = $this->dbs[$a]."site_content";
array_push($sel," UNION (SELECT $fields FROM $tbl WHERE $tbl.parent=$id AND $tbl.published=1 AND $tbl.deleted=0)");
}
$sql = implode("", $sel);
$sql= substr("$sql", 6);
$sql.=" ORDER BY $sort $dir;";

    $result = $this->dbQuery($sql);
    $resourceArray = array();
    for($i=0;$i<@$this->recordCount($result);$i++)  {
      array_push($resourceArray,@$this->fetchRow($result));
    }
    return $resourceArray;
  }

I've added to the _site_content table the field "prefix" , cos all the rest sites are located in subdirectories and have URL like _www.site.com/site/ . In tha field i store the part of the URL after the domain name, and add it in the link "Full Story" in the NewsListing snippet

ToDo: to get all the valiables direct from snippet's adress.. smth. like this [[News?site1=nic&newsid1=8?site2=isc&newsid2=10]] (example for 2 sites)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users