Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Create pages?

  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    86
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Create pages?

    Hiya!

    How do I create pages after one news article has been posted. I think my code uses an mysql query to get the data from the database so for each article from the database i need a new page for it.

    Thanks


    ~ David

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    It would help if you showed us what you have tried thus far.
    (BTW not necessary to create new page for each article. you simply populate a 'template' page with the appropriate content)

  • #3
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    It's great that you're creating your own CMS, but would WordPress be an easier solution?

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,233
    Thanks
    51
    Thanked 100 Times in 99 Posts
    Setup an admin control panel style structure and put in text boxes, image upload, etc whatever you need. Then when you fill it out and submit it, it inserts into the database. Next you'd create your template and extract the mysql values into the template where you want them. Then your done just keep making more pages by just using insert.

    Of course you will want to do Pagination as well with that.
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    86
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hiya guys, thanks for the replys

    This is my current code:

    PHP Code:
    <?php
    # PODpanel - "site_news.php" file - Written by SirTezza Modified by Blinger & lDaFreshKid.
    # Do not edit anything in this file, it could possibly lead to PODpanel not working properly.

        
    include("../_inc/config.php");
        include(
    "../_inc/functions.php");
        
    $ip $_SERVER['REMOTE_ADDR'];

        
    $info mysql_query("SELECT * from `info`"); 
        
    $info mysql_fetch_array($info);

        
    // Amount of pages either side of number (1 2 _3_ 4 5 etc.)
        
    $diffPages 0;
        function 
    header_colour($colour){
            switch (
    $colour) { 
         
            case 
    1:
                
    $colour "pink";
                break;
            case 
    2:
                
    $colour "green";
                break;
            case 
    3:
                
    $colour "yellow";
                break;
            case 
    4:
                
    $colour "orange";
                break;              
                    case 
    5:
                
    $colour "red";
                    break;
                    case 
    6:
                
    $colour "red";
                break;
                  
            }
            return 
    $colour;
        }

    if(
    $_POST['submit']){
        
    // Clean the submitted form
        
    $comment cleanTag($_POST['comment']);
        
    $habbo cleanTag($_POST['habbo']);
        
    $tstamp time();
        
    $ip getenv("REMOTE_ADDR");
        
    $id cleanTag($_POST['id']);

      
    // The colour of each row from the info DB
         
    $color1 $info[stripe1]; 
         
    $color2 $info[stripe2];
         
    // Var to start the header counter
         
    $header_colour 2;

        if(!
    $id){
            die(
    "Oops: Unexpected error!");
        }
        if(
    $habbo == "" || $comment == ""){
            die(
    "You cannot leave any fields blank");
        }
        
    // Insert the comment
        
    mysql_query("INSERT INTO comments_articles (comment, habboname, article, tstamp, ip) VALUES ('{$comment}', '{$habbo}', '{$id}', '{$tstamp}', '{$ip}')") or die(mysql_error());
        
        
    // Tell them the form was submitted
        
    echo("posted");

    # Insert action log
    $date date("d/m/y - h:ia");
    $insertLog "INSERT INTO `logs` ( `log` , `date` ) VALUES ('<strong>$habbo ($ip)</strong> has posted a comment<strong>$title</strong>', '$date')";
    mysql_query($insertLog) or die('MySQL Error.');

    } else if(
    $_GET['id']){
        
    // Get the id and clean it
        
    $id cleanTag($_GET['id']);
        

        
    // Get a colour from the DB
        
    $colourQ mysql_query("SELECT id FROM news ORDER BY id DESC");
        
    $colourR mysql_fetch_array($colourQ);
        
        
    $colour round($id $colourR[id]);
        
    // Get the news and the comments
        
    $getNews mysql_query("SELECT * FROM news WHERE category = 1 AND approved = 1 AND id = {$id} ORDER BY id DESC") or die(mysql_error());
        
    $newsRows mysql_fetch_array($getNews);

        
    $getCom mysql_query("SELECT * FROM comments_articles WHERE article = {$id} ORDER BY tstamp DESC") or die(mysql_error());


        
    // Show the news article again
        
    $id $newsRows['id'];
        
    $title strip_tags(stripslashes($newsRows['title']));
        
    $editor1 $show->news_article stripslashes(html_entity_decode($newsRows['editor1']));
        
    $poster $newsRows['poster'];
        
    $date1 $newsRows['date1'];

        
    $header_colour header_colour($colour);
        echo(
    "   <div class=\"center_{$header_colour}\">
                            <div id=\"middle-large\"> 
            $editor1<br><br>
            <i>Written by <a  class=\"$header_colour\" rel=\"noAJAX\" target=\"_blank\" href=\"http://www.habbo.com/home/{$poster}\">$poster</a> on <strong>$date1</strong></i>
                    </div>
                    <div id=\"bottom-large\"></div>
              "
    );


        
    // Get the amount of comments
        
    $numrows mysql_num_rows($getCom);
        
    // Echo out the comments
        
    if(!$numrows){
            
    // There are no comments
            
    echo("");
        } else {
            
    // Show the comments
            
    while($rows mysql_fetch_array($getCom)){
                
    $comment strip_tags($rows['comment']);
                
    $habboname $rows['habboname'];
                
    $article $rows['article'];
                
    $ip $rows['ip'];
                
    $timestamp date("m/d/y - h:ia"$rows['tstamp']);
            }
        
        }
        
        
    // Show the form to submit a comment
        
    echo("");
    } else {
        
    // Show the main news articles
        
    $limit 1;
        
    $page cleanTag($_GET['page']);
            
        if(!isset(
    $page)) {
            
    $page 1;
        }
        
        if(
    $page 1) {
            
    $page 1;
        }
        
            
        
    $getNews mysql_query("SELECT * FROM news WHERE category = 1 AND approved = 1 ORDER BY id DESC LIMIT $page, $limit") or die(mysql_error());

        
    $lastPageceilmysql_num_rows(mysql_query("SELECT * FROM news WHERE category = 1 AND approved = 1 ORDER BY id DESC")) / $limit );
        
        if(
    $page $lastPage) {
            
    $page $lastPage;
        }
        
        
    $pageNumber $pageNumber $limit;
        
    // If there are no articles
        
    if(mysql_num_rows($getNews) == 0){
              echo(
    "<div class=\"warning\"><center><b>There are currently no news articles. Please check back later!</center></b></div>");
        } else {
            
    // Var to start the header counter
            
    $colour 1;
            
    // Otherwise show the articles
            
    while($rows mysql_fetch_array($getNews)){
                
    $id $rows['id'];
                
    $title strip_tags(stripslashes($rows['title']));
                
    $editor1 $show->news_article stripslashes(html_entity_decode($rows['editor1']));
                
    $poster $rows['poster'];                         
                
    $date1 $rows['date1'];

                
    // The colour of each row from the info DB
                
    $color1 $info[stripe1]; 
                
    $color2 $info[stripe2];
                {
                    
    $header_colour header_colour($colour);
                    
    $commentQ mysql_query("SELECT * FROM comments_articles WHERE article='{$id}'");
                    
    $commentR mysql_num_rows($commentQ);
                    echo(
    "    <div class=\"center_{$header_colour}\">
                            <div id=\"middle-large\">                                                     
                    $editor1<br><br>
                    <i>Written by <a target=\"_blank\" class=\"$header_colour\" rel=\"noAJAX\" href=\"http://www.habbo.com/home/$poster\">$poster</a> on <strong>$date1</strong></i>
                            </div>
                            <div id=\"bottom-large\"></div>
    "
    );
                    
    $colour ++;
                    
    // If the colour count is 6 (we only have six colours), reset it back to 1
                    
    if($colour == 6){
                        
    $colour 1;
                    }
                }
            }
        
            
            
            
    $min $page $diffPages;
            
    $max $page $diffPages;
            
            if(
    $min 1){
                
    $dif $min;
                
    $min 1;
                
    $max $max $dif;
            }

            if(
    $max $lastPage){
                
    $dif $lastPage $max;
                
    $max $lastPage;
                
    $min $min $dif;
            }
            if(
    $min 1){
                
    $min 1;
            }
            for(
    $i=$min;$i<=$max;$i++) {
            
                if(
    $i == $page)
                {
                    echo(
    "<strong>$i</strong> | ");
                }
                else
                {
                    echo(
    "<a href='/staff/_frontend/site_news.php?page=$i'>$i</a> | ");
                }    

            }  
            
            if(
    $min 1){
                
    $min 1;
            }
        }
    }


      
    ?>

    </body>

    </html>
    Thanks

    ~ David

  • #6
    New Coder
    Join Date
    Dec 2011
    Posts
    86
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Bump

    Thanks guys

    ~ David

  • #7
    New Coder
    Join Date
    Dec 2011
    Posts
    86
    Thanks
    1
    Thanked 0 Times in 0 Posts
    bump


    ~ David

  • #8
    Regular Coder d'Anconia's Avatar
    Join Date
    Jan 2010
    Location
    Tempe, AZ
    Posts
    149
    Thanks
    16
    Thanked 6 Times in 6 Posts
    I am a bit of a beginner and am interested in the same subject. I know in PHP there are fopen() and fwrite() functions but thus far I have found them to possibly be more of a hassle than they're worth.

    A relevant question I have on this topic is: if you continuously use MySQL to insert database information into a template then is it even possible for the individual "pages" to be registered by search engines for SEO purposes? And would people be able to access one of those pages through a search engine?

    For example if you Google something and it shows up in Google results as a page from Wikipedia it includes page name and page description. Does Wikipedia use MySQL and if so is Google able to "crawl" through the Wikipedia MySQL database in order to register individual pages to be searched?

    Same thing goes for IMDb, if you Google a movie title the individual IMDb page will be one of the top results in Google. Are there actual "permanent" web pages for each movie or just one template that constantly inserts variables and whatnot from a MySQL database when requested?

    The problem I am having with fwrite() is that I want to write an entirely new web page, which means it will write a multi-line string inside the new file... and multi-line strings alone can be a hassle (I'm currently trying to use heredoc and nowdoc syntax but getting errors).

    Moreso since fwrite() is within <?php ?> tags it might make things more complicated because if I want to write PHP tags within the multi-line string sent to fwrite() then at what point would one have to escape certain characters?

    Of course if using MySQL database is still good for SEO purposes (so all of the web pages don't get skipped over my Google and other search engines) then inserting the values from the MySQL database would be the best way to go.

    Vernier, hopefully I haven't made the issue more confusing =P
    Last edited by d'Anconia; 04-24-2012 at 07:12 PM.
    Datagonia Web (My Portfolio)

    Powerful ideas for all lovers of personal and political freedom:
    Freedomain Radio
    Free Talk Live

  • #9
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,378
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    If you go to some WordPress sites and see URL's like ... mysite.com/parts-online

    You'll see that there are no specific PHP variables in the URL, yet it is processing
    a whole dynamic page using PHP/MySQL. This is done using Rewrite Rules (.htaccess).
    That's the type of thing you'll want to do ... for simplifying and making clean URLs.

    WordPress calls them "permalinks" or "pretty permalinks".

    More info here:
    http://www.google.com/search?q=rewri...rl&btnG=Search



    .


  •  

    Posting Permissions

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