Dynamic content from a different database

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Dynamic content from a different database

Post by Nullig »

What I usually do is copy the code from the existing page into a User Defined Tag, including all of the database connection info, reformat it the way I want and call that tag within the page/template I want it on.

Important Note: Add "adodb_connect();" as the last line of your tag, so you reconnect with the cms database.

Nullig
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Dynamic content from a different database

Post by Nullig »

If you create a "detail" page in CMSMS with another UDT to get the user info, then you should be able to make the link like this:

  index.php?page=detail&id=userid

Note:  you should deselect the "show in menu" option for the detail page.

Nullig
Last edited by Nullig on Thu Jun 14, 2007 2:51 pm, edited 1 time in total.
olavt

Re: Dynamic content from a different database

Post by olavt »

I am using another database with CMSMS. (Technically I have one datebase with many non-CMSMS tables, as my ISP will only let me have one database).

The following user defined tag will give the information on this page (main section): http://www.torvund.net/guitar/index.php?page=artists

Tag:
$start_offset = $params['start'] ? $params['start'] : "0";
$num = $params['num'] ? $params['num'] : "50";

$artists = @mysql_query( 'SELECT * FROM person WHERE LastName LIKE "' . $params['letter'] . '%" ORDER BY LastName, FirstName LIMIT ' . $start_offset . ', ' . $num );

$num_rows = mysql_num_rows( $artists );

echo 'fant ' . $num_rows . ' artister
';
while ($row = mysql_fetch_array($artists)) {
  echo '
' . $row['LastName'] . ', ' . $row['FirstName'] . '   Books

DVD

RecordingsCDsEquipment';



  /* for instance Artist, The */
}

echo '';

echo '';
if ( (int) $start_offset - (int) $num >= 0 ) {
  echo ' ';
}
echo ' ';
echo '  ';

____

As you can see, it creates URLs listed on the site where this tag is included. By clicking on one of the links you will open a new page where a tag with this content is included (one example of the result - if you choose The Beatles, can be found at http://www.torvund.net/guitar/index.php ... s&aid=1132 ):

$artist_id = mysql_real_escape_string($params['aid']);

// Hent artistinfo
$artist = @mysql_query("SELECT * FROM person WHERE PersonID=" . $artist_id . ";");

$row = mysql_fetch_array($artist);
$firstname = $row['FirstName'];
$lastname = $row['LastName'];
$memo = $row['Memo'];

echo '' . $row['FirstName'] . ' '  . $row['LastName'] .' - books';



  echo '
Books -

DVD -
Recordings - CDs - Equipment ';

echo '' . $row['Memo'] . '';


//New Books

echo 'New books (or books with updated information)';

if ( isset( $params['frmid'] )){
$newbooks = @mysql_query('SELECT * FROM linkpersonbook, book WHERE PersonID= ' .$params['aid'] . ' AND linkpersonbook.BookID=book.BookID AND
Format="' . $params['frmid'] . '" AND oppdatert >= ' . strtotime("-3 months") . ' ORDER BY Oppdatert DESC;');}

else {$newbooks = @mysql_query('SELECT * FROM linkpersonbook, book WHERE PersonID= ' .$params['aid'] . ' AND linkpersonbook.BookID=book.BookID AND oppdatert >= ' . strtotime("-3 months") . ' ORDER BY Oppdatert DESC;');}

while ($row = mysql_fetch_array($newbooks)) {

echo '
 
   
     
More  >>

     
     
       
         
            ' . $row['BookTitle'] .  '
' . $row['Subtitle'] . '
         
         
            RefNr: ' . $row['RefNr'] . '
         
       
     
     
     
      Order From:
 
';
if ($row['SMPlus']) {
  echo 'SheetmusicPlus';

if ($row['MR']) {
  echo 'MusicRoom';
}

if ($row['ASIN']) {
  echo 'Amazon UK
Amazon US';
}

if ($row['ISBN']) {
echo'





';}

echo      '
   
 

';
}


/* $books = @mysql_query('SELECT * FROM linkpersonbook AS lp, book AS b WHERE lp.PersonID="' . $artist_id .  '" AND linkpersonbook.BookID=book.BookID;'); */

// Hent alle bøker av/om artist, sortert etter kategori, så alfabetisk
if ( isset( $params['frmid'] )){
$books = @mysql_query('
SELECT b.*, r.*, p.FirstName
FROM book AS b, person AS p, role AS r, linkpersonbook as lp
WHERE lp.PersonID=' .$params['aid'] . ' AND
p.PersonID=lp.PersonID AND
r.RoleID=lp.RoleID AND
b.BookID=lp.BookID AND
Format="' . $params['frmid'] . '"
ORDER BY Sort1, b.BookTitle;');}

else {$books = @mysql_query('
SELECT b.*, r.*, p.FirstName
FROM book AS b, person AS p, role AS r, linkpersonbook as lp
WHERE lp.PersonID=' .$params['aid'] . ' AND
p.PersonID=lp.PersonID AND
r.RoleID=lp.RoleID AND
b.BookID=lp.BookID
ORDER BY Sort1, b.BookTitle;');}

echo '';
  $old_role = "";
  while ( $book = mysql_fetch_array($books) ) {
    $role = $book['Role'];

    // Print rolle overskrift, hvis det er en ny kategori
    if ($role != $old_role) {
      echo 'Books ' . $role .' ' . $firstname . ' ' . $lastname . '';
    }

    // Print info om bok
    echo '
 
   
     
     
      More  >>
   
    ';
    echo '
   
     
       
         
              ' . $book['BookTitle'] .  '' . $book['Subtitle'] . '
Level: ' . $row['GLevel'] . ',  ' . $row['Pages'] . ' pages
         
       
       
          RefNr: ' . $book['RefNr'] . '
       
     
   
   
      Order From:
      ';
      if ($book['SMPlus']) {
        echo 'SheetmusicPlus';
      } 
      if ($book['MR']) {
        echo 'MusicRoom';
      }

      if ($book['ASIN']) {
        echo 'Amazon UK
      Amazon US';
    }

if ($book['ISBN']) {
echo'









';
      }
      echo '
   
  ';

    // Backup forrige boks rolle
    $old_role = $role;
  }
echo "";

-----

The links in the right column on this page is also taken from a non-CMSMS table in the database, and the navigation to the left is used to narrow down the result by adding another paramter.

As I am technically using the same database, I do not have to worry about opening and closing the database. But apart from that, I think that it shows one example on how to extract information from another database and include it on CMSMS pages.
Pierre M.

Re: Dynamic content from a different database

Post by Pierre M. »

For people as lazy as me, there are the out of the box FormBuilder and FormBrowser modules as well ;)
Pierre M.
Post Reply

Return to “CMSMS Core”