<?php
  // define the vars + include the header
  $page_title = "<a href=http://rebecca.hallqvist.se/schooner/wheatblog/index.php title=tillbaks>schooner</a> :: kategorier";
  $prefix = "../";
  $template = 3;
  include("$prefix" . "whp_header.inc"); 
?>

<?php
    // read in the connection settings
    require("wheatblog_settings.inc");

    // parse the passed vars into something useful 
    // also check for nulls
    $the_category = $_GET['the_category'];

    // connect to the RDBMS
    $db = mysql_connect("$site","$user","$pass") 
        or die("<h2>Could not connect to database server</h2><p>Check passwords and sockets</p>");

    // select the database
    mysql_select_db("$database",$db) 
        or die("<h2>Could not select database $database</h2><p>Check database name</p>");

    // select posts in the database that match the category
    // should paginate this in the future
    $result = mysql_query("select * 
        from $database_table
        where category = '$the_category' 
        order by year DESC, month DESC, day DESC",$db) 
        or die("<h2>Could not select posts</h2>");

    while($row = mysql_fetch_array($result)) {
        $the_id = $row["id"];
        $the_day = $row["day"];
        $the_month = $row["month"];
        $the_date = $row["date"];
        $the_year = $row["year"];
        $the_category = $row["category"];

            // parse out the category id into its string value
            $result2 = mysql_query("select *   
                from $database_table_categories   
                where id = '$the_category'",$db)
                or die("<h2>Could not select category</h2>"); 

            while($row2 = mysql_fetch_array($result2)) {
                $the_category_name = $row2["category"];
            }

        $the_showpref = $row["showpref"];
        $the_title = $row["title"];
        $the_body = $row["body"];
        $number_of_comments = $row["number_of_comments"];

    // post
        echo("<div class='indent'>\n");
        echo("<span class='desc_header'>$the_day" . ", " . "$the_date" . "/" . "$the_month" . " " . "$the_year" . " :: " . "$the_title" . "</span><br>\n");
        echo("$the_body" . "<br>\n");
        echo("[<a href='view_by_category.php?the_category=$the_category'" . "'>" . "$the_category_name" . "</a>] ");
        echo("<!-- [" . "<a href='view_by_permalink.php?the_id=$the_id'" . "'>id: " . "$the_id" . "</a>] -->\n");
        echo("[" . "<a href='view_by_permalink.php?the_id=$the_id'" . "'>" . "kommentarer ($number_of_comments)" . "</a>]\n");  
        echo("</div>\n\n");
    }

    echo("<!-- generated by wheatblog: stop -->\n\n");
?>

<?php
  // include the footer
  include("$prefix" . "whp_footer.inc");
?>