SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Denmark
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php FastTemplate ?

    PHP Code:

    // Please help me !!!
    How do i turn this php-document into a Php FastTemplate ???



    <html>
    <head>

    <title>The Freakshow</title>

    <link rel="stylesheet" href="../style/style.css" type="text/css">

    </head>

    <body>

    <?php

    $dbcnx 
    mysql_connect('localhost''root''');
    mysql_select_db('jokes');

    $id $_GET['id'];

    $freakshow "SELECT JokeText, headline, AID, Name, EMail FROM jokes, authors WHERE jokes.id='$id' AND authors.id=AID";

    $forsidetext = @mysql_query($freakshow);
    $text mysql_fetch_array($forsidetext);

    $forside $text['JokeText'];
    $header  $text['headline'];
    $billed  $text['Name'];
    $AID     $text['AID'];
    $navn    $text['EMail'];

    // Bold and italics
    $forside str_replace(array('[b]','[B]'),'<strong>',$forside);
    $forside str_replace(array('[b]','[B]'),'<strong>',$forside);
    $forside str_replace(array('[eb]','[EB]'),'</strong>',$forside);
    $forside str_replace(array('[i]','[I]'),'<em>',$forside);
    $forside str_replace(array('[ei]','[EI]'),'</em>',$forside);

    // Hyperlinks
    $forside eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])""<a href=\"\\1://\\2\\3\" target=\"_blank\" class=\"admin\"><strong>\\2\\3</strong></a>"$forside);


    // Paragraphs and line breaks
    $forside ereg_replace("\r",'',$forside);
    $forside ereg_replace("\n\n",'</p><p>',$forside);
    $forside ereg_replace("\n",'<br />',$forside);


    // slut på freakshows forside //


    $sql 'SELECT jokes.ID, headline, Name, AID, EMail FROM jokes, authors, jokelookup
                 WHERE AID=authors.ID AND JID=jokes.ID'
    ;

             
    $cat $_GET['cat'];
    $sql .= " AND CID='$cat' ORDER BY ID DESC";

    // Get category name
    $sqlcat "SELECT Name from categories WHERE ID='$cat'";
    $catresult mysql_query($sqlcat);
    $catdetail mysql_fetch_array($catresult);
    $catname htmlspecialchars($catdetail['Name']);


    ?>


    <table border="0" align="center" cellspacing="0" cellpadding="3" width="430">

    <tr><td>

    <?php

    $freak 
    = @mysql_query($sql);

    if (!
    $sql) {

    die(
    '<p>Der skete følgende fejl!<br /> Skriv til webmasteren på [email]kasper@voice.dk[/email]' .
          
    'Error: ' mysql_error() . '</p>');

    }


    $c 0;

    // start på while-loop //

    while ($links mysql_fetch_array($freak)) {

             
    $id $links['ID'];
     
    $overskrift $links['headline'];

          
    $c++;


    // Remove any custom tags in the joke text. They are not needed in this preview.
    $joketext ereg_replace('\[[-_./a-zA-Z0-9!&%#?+,\'=:~]+]','',$overskrift);

    // Finally, make it safe to display in an HTML document

    $joketext htmlspecialchars($overskrift);

    if ( 
    $c == ) {

    echo 
    "<table border=\"0\" width=\"0\" cellpadding=\"3\">\n<tr>\n";

    }


    echo 
    "<td height=\"20\"><a href=\"voice.php?cat=$cat&id=$id\" class=\"voice\"><b>$overskrift</b></a></td>\n";

    // bestemmer hvor mange celler der skal være i hver row //

    if ( $c == ) {

    echo 
    "</tr>\n</table>\n\n";

    $c 0;

    }


     }
     
    // End while-loop //


    if ( <= $c OR <= $c ) {

    echo 
    "</tr>\n</table>";

    }
     

    ?> 

    </td></tr>


    <tr><td height="30"><? echo "<strong>$header</strong>"?></td></tr>



    <tr><td>

    <? 

    if ( $AID == ) {

    echo 
    "$forside\n";

    }

    else {

    echo 
    "<img src=\"$billed\" alt=\"$navn\">$forside\n";

    }

    ?>

    </td></tr>

    </table>


    </body>
    </html>

  2. #2
    SitePoint Addict lveale's Avatar
    Join Date
    Jun 2001
    Location
    Dublin
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    first design your page exactly how you want it to look, perhaps with one or two rows in place of where you will put all your database results.

    Then, whereever you have dynamic data, put a placeholder in i.e. {TITLE}.

    Then use the logic that you have above in a new PHP file to get the required rows from the table, calling the required template(s) as neccessary.

    The examples that come with FastTemplate are pretty comprehensive.

  3. #3
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why use template engines ?, read this: http://www.sitepointforums.com/showt...threadid=67849
    - website


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •