FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Replacing a marker with multipule content items





JVermolen
As the subject say's im trying to replace a marker in a user defined template.
Here is the complete strory behind it:

Im trying to create a CMS, witch lets users define a template with some costum markers.
Now i can load the temlate to the index.php file with its template, stylesheet and everything
i know how to replace the marker if i have only one content item, but the problem is i have multipule.

I have this in the content table form my database:
Code:

id     pid     title         content                                                  area
1      1       De titel      Lorem ipsum dolor sit amet, consectetur adipiscing...    main
2      1       Titel 2       Lorem ipsum dolor sit amet, consectetur adipiscing...    main


And the code i have in index.php so far:
Code:

<?php
   include ('admin/core/pages/frontendview.php');
   $Sample = new view;
   $Sample->viewpage();
   
   ?>   


and frontendview.php functiun viewpage() contains:
Code:

          function viewpage() {
            $this->getHead();
            $this->getStylesheet();
            $this->getTemplate();
          }

// getTemplate () contains the code you need:
function getTemplate() {
   if (!$_GET) {
            $id = '1';
         } else {
            $id = $_GET['id'];
         }
         $query = "SELECT * from pages  WHERE ID = '$id'";
         $result = mysql_query($query) or die (mysql_error());
         $row = mysql_fetch_array($result);
          if($row['tid'] == '' || $row['tid'] == '0') {
             $pid = $row['pid'];
             $tid = '';
            do {
                $query2 = "SELECT * FROM pages WHERE id = '$pid'";
                $result2 = mysql_query($query2) or die (mysql_error());
                $row2 = mysql_fetch_array($result2);
                $tid = $row2['tid'];
                $pid = $row2['pid'];
             }
             while ($tid == '' || tid == '0');
          }
          else {
             $tid = $row['tid'];
          }
         $query = "SELECT * from template  WHERE ID = '$tid'";
         $result = mysql_query($query) or die (mysql_error());
         $row = mysql_fetch_array($result);
         $template = $row['template'];
         $fh = fopen($template, 'r');
         $theData = fread($fh, filesize($template));
         fclose($fh);
         $maincontentmarker = $row['mainmarker'];
         $query2 = "SELECT * from content  WHERE pid = '$id' AND area = 'main'";
         $result2 = mysql_query($query2) or die (mysql_error());
         $query = "SELECT * from content  WHERE pid = '$id'";
         $result = mysql_query($query) or die (mysql_error());

         while ($row = mysql_fetch_array($result)) {
            $title = $row['title'];
            $title = str_replace ($title, "<h1>" . $title . "</h1>", $title);
            $content = $row['content'];
            $content = str_replace($content, "<div id='maincomlumncontent'>" . $content . "</div>", $content);
                $maincontentmarker = $title . $content
            }
            echo str_replace($maincontentmarker, $maincontentcolumn, $theData);
         }


So in short it needs to replace ##main## (witch is the marker) with the content (witch include a title and the content)
Who can help me out?
jmraker
You can try the substr_replace function
http://us2.php.net/manual/en/function.substr-replace.php

Code:
<?php
$markerStart = strpos($maincontentmarker, $maincontentmarker);
if($markerStart != false){
  $theData = substr_replace($theData, $maincontentcolumn, $markerStart, strlen($maincontentmarker));
  // remove duplicate markers here with a loop until strpos returns false
  while($markerStart = strpos($maincontentmarker, $maincontentmarker) != false){
     $theData = substr_replace($theData, '', $markerStart, strlen($maincontentmarker));
  }
  // or just use str_replace
  $theData = str_replace($maincontentmarker, '', $theData);
 echo $theData
}
?>
Related topics
Same Key Words are in Many of my site pages
JQuery Sliding Tab Menu
Any thing suit for beginners better than FrontPage
Battlefield 2
Brand-new content-sensive auction advertising service
My hiking/survival gear, explained. (Warning, ~90 pics)
10 Things I've learnt in 2 weeks
The worlds shortest and laziest Mambo tutorial.
Simple or Bulky/Heavy ?
Mambo Content Problem
Why use IE?
Interview: Derek Liu, Gaia Online Anime Community
751 Useful Windows XP Files
WOW
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.