Results 1 to 4 of 4

Thread: Simple CMS

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default Simple CMS

    Hey all...

    I'm trying to build a simple CMS system to easily update a "recent updates/news" section on a website I'm building.

    This is the first time I'm doing something like this, so please bear with me.

    I followed a tutorial at php-mysql-tutorials.com and learned a lot.

    I have it working as the tutorial says. I wanted to tweak it a little, however. So I don't know how I would do this.


    Here is the PHP. This lists all of the available articles in the DB and then makes a list.

    PHP Code:
    <?php
    include 'config.php';
    include 
    'opendb.php';

    // if no id is specified, list the available articles
    if(!isset($_GET['id']))
    {
       
    $self $_SERVER['PHP_SELF'];

       
    $query "SELECT id, title FROM news ORDER BY id";
       
    $result mysql_query($query) or die('Error : ' mysql_error()); 

       
    // create the article list 
       
    $content '<ol>';
       while(
    $row mysql_fetch_array($resultMYSQL_NUM))
       {
          list(
    $id$title) = $row;
          
    $content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n";
       }

       
    $content .= '</ol>';

       
    $title 'Available Articles';
    } else {
       
    // get the article info from database
       
    $query "SELECT title, content FROM news WHERE id=".$_GET['id'];
       
    $result mysql_query($query) or die('Error : ' mysql_error()); 
       
    $row mysql_fetch_array($resultMYSQL_ASSOC); 

       
    $title $row['title'];
       
    $content $row['content'];


    include 
    'closedb.php';
    ?>

    <html>
    <head>
    <title>
    <?php echo $title?>
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">

    // ... some css here to make the page look nicer

    </style>
    </head>
    <body>
    <table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699">
    <tr> 
    <td bgcolor="#FFFFFF">
    <h1 align="center"><?php echo $title?></h1>
    <?php 
    echo $content;

    // when displaying an article show a link
    // to see the article list
    if(isset($_GET['id']))

    ?>
    <p>&nbsp;</p>
    <p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Article List</a></p>
    <?php
    }
    ?> 
    </td>
    </tr>
    </table>
    </body>
    </html>

    What I want to do is show ALL of the articles. So, how would i do this without the whole "id" bit.

    The second part would be that I need a way to delete an entry for the mySQL table (i haven't attempted this yet, might be able to figure it out on my own)

    Thanks!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    http://php-mysql-tutorial.com
    All you need to know is there.

    For showing all entries, just don't use a WHERE, and then you get all of the results returned. Loop through them to display.

    To delete, use the DELETE command.

    Both are covered in detail in the tutorial.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by djr33 View Post
    http://php-mysql-tutorial.com
    All you need to know is there.

    For showing all entries, just don't use a WHERE, and then you get all of the results returned. Loop through them to display.

    To delete, use the DELETE command.

    Both are covered in detail in the tutorial.
    I've been to that tutorial and the reason for me posting here is because that didn't answer all of my questions.

    I tried editing this:

    PHP Code:
    $query "SELECT title, content FROM news WHERE id=".$_GET['id']; 
    to this:

    PHP Code:
    $query "SELECT title, content FROM news; 
    but that gives an error:
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\article1.php on line 30
    Line 30:
    PHP Code:
    $title $row['title']; 


    Edit:
    Nevermind, figured it out.

    <?php
    include 'config.php';
    include 'opendb.php';

    $query = "SELECT title, content FROM news";
    $result = mysql_query($query);

    while($row = mysql_fetch_assoc($result))
    {
    echo "<div class=border style='text-align:left'><div style='margin:5px;background-color:f9f7f8;'> {$row['title']} <br>" .
    "{$row['content']} <br><br></div>";
    }
    include 'closedb.php';
    ?>
    Last edited by Medyman; 07-23-2007 at 08:03 PM.

  4. #4
    Join Date
    Jul 2007
    Location
    California
    Posts
    177
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Gotta love the old " character eh?

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
  •