TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 20, 2024, 04:33:48 AM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,195
  • Total Topics: 21,220
  • Online today: 114
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 74
  • Total: 74

[block] Approved Articles / Sorted, Paginated, Categorized, & Customized

Started by tim antley, September 21, 2008, 11:13:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

Try this code and see if it works. It worked on my SMF2 site.
// Articles By Date
// September 24, 2008 | Tim Antley
// Version II (Already)

// Displays x Number Of Approved Articles Per Page / Sorted By Date (Latest To Oldest)
// Simple Pagination In Table Output Form
// Retrieve URL Variables To Parse

global $db_prefix, $scripturl, $context;

// script variables for customization
$show_date = true; // show date in table; true or false
$show_views = true; // show number of views for each article
$show_author = false; // show name of author in table; true or false
$show_header = true; // show table header w/ field values
$use_theme_css = false; // use theme CSS or set using colors below

// will use numeric values if $use_theme_css set to false
$css_row = '999999'; // background color for first row; 999999 = light gray
$css_row_alt = '666666'; // alternating row color; 666666 = dark gray

$link_width = 60; // max length of article name in table
$link_target = '_blank'; // target for article link; _self = same window, _blank = new window
$link_color = 'FF9900'; // hyperlink color; actually gets set in custom CSS block below

$limit = 20; // number of results to display per page
$category = 0; // number of category, 0 = no specified category

$page = ''; // set to article # that this script is in

// no need to edit past this point! warranty void if modified...

$article = array();
$limits = array(10, 20, 30, 40, 50);
$row_class = '';

// put URL variables into array
parse_str($_SERVER['QUERY_STRING'], $url_vars);

$start = 0; // set to 0; will check for URL value soon

// check for 'cat' and 'limit' values via GET first; use POST value instead, if set
if(!empty($_GET['cat'])) $category = $_GET['cat'];
if(isset($_POST['cat'])) $category = $_POST['cat'];

if(isset($_GET['limit'])) $limit = $_GET['limit'];
if(isset($_POST['limit'])) $limit = $_POST['limit'];

if($limit < 0 || !in_array($limit, $limits)) $limit = 10;

$url_link = ''; // set to null

// build url string from array (exclude script variables)
foreach($url_vars as $key => $value)
{
$key = strtolower($key); // restrict to lowercase

if($key != 'page' && $key != 'start' && $key != 'cat' && $key != 'limit')
{
$url_link .= $key . '=' . $value . '&';
}
}

$url_link .= 'limit=' . $limit . '&';

// custom CSS block to set style
if(!$use_theme_css)
{
echo '
<style type="text/css">
.article_nav a:link, a:hover
{
text-decoration: underline;
color: #' . $link_color . ';
}
</style>';

$css = 'style=background: #';
}
else
{
$css = 'class="windowbg';
$css_row = '';
$css_row_alt = '2';
}

// crude way to get page name; $context SHOULD have this somewhere...
if(!empty($_GET['page'])) $page = $_GET['page'];

// get starting point from URL and set to integer value; already defaulted to 0 if not set
if(!empty($_GET['start'])) $start = intval($_GET['start']);

$query = tpdb_query(
"SELECT id, value1, type
FROM {$db_prefix}tp_variables
WHERE type = 'category'
", __FILE__, __LINE__);

$cats[0] = array('id' => 0, 'cat_name' => 'No Specific Category'); // pre-populate generic category

while ($row = tpdb_fetch_assoc($query)) // populate category array
{
$cats[] = array(
'id' => $row['id'],
'cat_name' => $row['value1'],
);
}

if($category != 0)
{
$query = tpdb_query(
    "SELECT *
FROM {$db_prefix}tp_articles
WHERE approved = 1
AND category = {$category}
", __FILE__, __LINE__);
}
else
{
$query = tpdb_query(
    "SELECT *
FROM {$db_prefix}tp_articles
WHERE approved = 1
", __FILE__, __LINE__);
}
$total_rows = tpdb_num_rows($query); // get number of articles approved

if($category != 0)
{
$query = tpdb_query(
    "SELECT id, value1
FROM {$db_prefix}tp_variables
WHERE id = {$category}
", __FILE__, __LINE__);

$cat_desc = mysql_fetch_array($query);
$cat_desc = $cat_desc['value1'];

if(empty($cat_desc)) $cat_desc = 'No Category Description In Database';

$query = tpdb_query(
    "SELECT id, date, subject, shortname, author, views, category
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
AND category = {$category}
ORDER BY date DESC
LIMIT {$start}, {$limit}
", __FILE__, __LINE__);

}
else
{
$cat_desc = 'No Specified Category';

$query = tpdb_query(
    "SELECT id, date, subject, shortname, author, views, category
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
ORDER BY date DESC
LIMIT {$start}, {$limit}
", __FILE__, __LINE__);
}

while ($row = tpdb_fetch_assoc($query)) // place article info into $article array
{
$article[] = array(
'id' => $row['id'],
'date' => $row['date'],
'subject' => $row['subject'],
'shortname' => $row['shortname'],
'author' => $row['author'],
'views' => $row['views'],
'category' => $row['category'],
);
}

// display category select menu form w/ submit button
echo '<form name="article_menu" method="POST" action="' . $scripturl . '?' . $url_link . 'page=' . $page . '">';
echo '<select name="cat">';

foreach($cats as $item)
{
echo '<option ' . ($item['id'] == $category ? 'selected ' : '') . 'value="' . $item['id'] . '">' . $item['cat_name'] . '</option>';
}
echo '</select>  ';

echo '<select name="limit">';
foreach($limits as $limit_sel)
{
echo '<option ' . ($limit == $limit_sel ? 'selected ' : '') . 'value="' . $limit_sel . '">' . $limit_sel . '</option>';
}
echo '</select> Per Page ';

echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';

// display article table with info
if(count($article) > 0)
{

// simple pagination routine; took entirely too long to get this right...
if($start + $limit <= $total_rows)
{
$next_pg = $start + $limit;
}
else
{
$next_pg = $total_rows;
}

if($start - $limit >= 0)
{
$prev_pg = $start - $limit;
}
else
{
$prev_pg = 0;
}

// start of top navigation block
echo '<hr /><div class="titlebg">' . $total_rows . ' Article' . ($total_rows > 1 ? 's' : '') . ' Available | ' . $cat_desc . '</div>';

echo '<div class="titlebg" class="article_nav">';

if($start > 1) echo '<a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $prev_pg . '&cat=' . $category . '">Previous Page</a> | ';

echo $start + 1 . ' - ' . $next_pg;

if($next_pg < $total_rows) echo ' | <a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $next_pg . '&cat=' . $category . '">Next Page</a>';

echo '</div><hr />';

echo '<table border="0" cellspacing="0" cellpadding="0">';

if($show_header) // display a table header
{
echo '<tr class="windowbg2">';

if($show_date) echo '<td align="right">  Date :</td>';
if($show_views) echo '<td align="center">  Views  </td>';
if($show_author) echo '<td align="left">  Author  </td>';

echo '<td align="left"> Article Title </td>';
}

foreach($article as $item)
{
if(empty($item['shortname'])) $item['shortname'] = $item['id']; // make shortname = id if it doesn't already exist (for JPDeni!)

if($use_theme_css)
{
echo '<tr class="windowbg' . ($row_class = $row_class == $css_row ? $css_row_alt : $css_row) . '">';
}
else
{
echo '<tr style="background: #' . ($row_class = $row_class == $css_row ? $css_row_alt : $css_row) . '">';
}

if($show_date)
{
echo '<td align="right">  ' . date("M j, Y", $item['date']) . ' :</td>';
}

if($show_views) echo '<td align="center"> (' . $item['views'] . ')' . '</td>';
if($show_author) echo '<td align="left"> (' . $item['author'] . ')</td>';

echo '<td align="left"> <a href="' . $scripturl . '?page=' . $item['shortname'] . '" target="' . $link_target . '">';
echo substr($item['subject'], 0, $link_width) . '</a>';

echo ' </td></tr>';
}

echo '</table>';
}
else // no articles = simple notice of nothing found; no table used
{
echo '<div class="titlebg">No Available Articles At This Time</div><hr />';
}

// start of navigation block
echo '<hr /><div class="titlebg" class="article_nav">';

if($start > 1) echo '<a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $prev_pg . '&cat=' . $category . '">Previous Page</a> | ';

echo $start + 1 . ' - ' . $next_pg;

if($next_pg < $total_rows) echo ' | <a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $next_pg . '&cat=' . $category . '">Next Page</a>';

echo ' | Total Articles : ' . $total_rows;

echo '</div>';

tpdb_free_result($query); // free up memory (nice to do)

Rafferty

Beautiful, thx very much Ich


The Wizard

Ok but this is a waste of time...
Link to my site: http://www.tribeuniverse.com
SMF version: 2.0 RC4
TP version: 1.0 RC1
Default Forum Language: English
Theme name and version:CurveLife
Browser Name and Version: IE
Mods installed:Tiny Portal, Aeva Media
Related Error messages: None

Now that I have gotten that stuff out of the way....

I have changed your code a little for my use and so I'll post it here too -

echo '<div style="background-image:url(\'http://www.tribeuniverse.com/tribe-images/tribe-images/big_backgrounds/nature.jpg\');"> ';


// Articles By Date
// September 24, 2008 | Tim Antley
// Version II (Already)

// Displays x Number Of Approved Articles Per Page / Sorted By Date (Latest To Oldest)
// Simple Pagination In Table Output Form
// Retrieve URL Variables To Parse

global $db_prefix, $scripturl, $context;

// script variables for customization
$show_date = false; // show date in table; true or false
$show_views = false; // show number of views for each article
$show_author = false; // show name of author in table; true or false
$show_header = false; // show table header w/ field values
$use_theme_css = false; // use theme CSS or set using colors below

// will use numeric values if $use_theme_css set to false
$css_row = ''; // background color for first row; 999999 = light gray
$css_row_alt = ''; // alternating row color; 666666 = dark gray

$link_width = 60; // max length of article name in table
$link_target = '_self'; // target for article link; _self = same window, _blank = new window
$link_color = '0000FF'; // hyperlink color; actually gets set in custom CSS block below

$limit = 20; // number of results to display per page
$category = 6; // number of category, 0 = no specified category

$page = ''; // set to article # that this script is in

// no need to edit past this point! warranty void if modified...

$article = array();
$limits = array(10, 20, 30, 40, 50);
$row_class = '';

// put URL variables into array
parse_str($_SERVER['QUERY_STRING'], $url_vars);

$start = 0; // set to 0; will check for URL value soon

// check for 'cat' and 'limit' values via GET first; use POST value instead, if set
if(!empty($_GET['cat'])) $category = $_GET['cat'];
if(isset($_POST['cat'])) $category = $_POST['cat'];

if(isset($_GET['limit'])) $limit = $_GET['limit'];
if(isset($_POST['limit'])) $limit = $_POST['limit'];

if($limit < 0 || !in_array($limit, $limits)) $limit = 10;

$url_link = ''; // set to null

// build url string from array (exclude script variables)
foreach($url_vars as $key => $value)
{
$key = strtolower($key); // restrict to lowercase

if($key != 'page' && $key != 'start' && $key != 'cat' && $key != 'limit')
{
$url_link .= $key . '=' . $value . '&';
}
}

$url_link .= 'limit=' . $limit . '&';

// custom CSS block to set style
if(!$use_theme_css)
{
echo '
<style type="text/css">
.article_nav a:link, a:hover
{
text-decoration: underline;
color: #' . $link_color . ';
}
</style>';

$css = 'style=background: #';
}
else
{
$css = 'class="windowbg';
$css_row = '';
$css_row_alt = '2';
}

// crude way to get page name; $context SHOULD have this somewhere...
if(!empty($_GET['page'])) $page = $_GET['page'];

// get starting point from URL and set to integer value; already defaulted to 0 if not set
if(!empty($_GET['start'])) $start = intval($_GET['start']);

$query = tpdb_query(
"SELECT id, value1, type
FROM {$db_prefix}tp_variables
WHERE type = 'category'
", __FILE__, __LINE__);

$cats[0] = array('id' => 0, 'cat_name' => 'No Specific Category'); // pre-populate generic category

while ($row = tpdb_fetch_assoc($query)) // populate category array
{
$cats[] = array(
'id' => $row['id'],
'cat_name' => $row['value1'],
);
}

if($category != 0)
{
$query = tpdb_query(
"SELECT *
FROM {$db_prefix}tp_articles
WHERE approved = 1
AND category = {$category}
", __FILE__, __LINE__);
}
else
{
$query = tpdb_query(
"SELECT *
FROM {$db_prefix}tp_articles
WHERE approved = 1
", __FILE__, __LINE__);
}
$total_rows = tpdb_num_rows($query); // get number of articles approved

if($category != 0)
{
$query = tpdb_query(
"SELECT id, value1
FROM {$db_prefix}tp_variables
WHERE id = {$category}
", __FILE__, __LINE__);

$cat_desc = mysql_fetch_array($query);
$cat_desc = $cat_desc['value1'];

if(empty($cat_desc)) $cat_desc = 'No Category Description In Database';

$query = tpdb_query(
"SELECT id, date, subject, shortname, author, views, category
FROM {$db_prefix}tp_articles
WHERE approved = 1
AND category = {$category}
ORDER BY date DESC
LIMIT {$start}, {$limit}
", __FILE__, __LINE__);

}
else
{
$cat_desc = 'No Specified Category';

$query = tpdb_query(
"SELECT id, date, subject, shortname, author, views, category
FROM {$db_prefix}tp_articles
WHERE approved = 1
ORDER BY date DESC
LIMIT {$start}, {$limit}
", __FILE__, __LINE__);
}

while ($row = tpdb_fetch_assoc($query)) // place article info into $article array
{
$article[] = array(
'id' => $row['id'],
'date' => $row['date'],
'subject' => $row['subject'],
'shortname' => $row['shortname'],
'author' => $row['author'],
'views' => $row['views'],
'category' => $row['category'],
);
}

// display article table with info
if(count($article) > 0)
{

// simple pagination routine; took entirely too long to get this right...
if($start + $limit <= $total_rows)
{
$next_pg = $start + $limit;
}
else
{
$next_pg = $total_rows;
}

if($start - $limit >= 0)
{
$prev_pg = $start - $limit;
}
else
{
$prev_pg = 0;
}

// start of top navigation block
echo '<hr /><div class="titlebg">' . $total_rows . ' Article' . ($total_rows > 1 ? 's' : '') . ' Available | ' . $cat_desc . '</div>';

echo '<div class="titlebg" class="article_nav">';

if($start > 1) echo '<a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $prev_pg . '&cat=' . $category . '">Previous Page</a> | ';

echo $start + 1 . ' - ' . $next_pg;

if($next_pg < $total_rows) echo ' | <a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $next_pg . '&cat=' . $category . '">Next Page</a>';

echo '</div><hr />';

echo '<table border="0" cellspacing="0" cellpadding="0">';

if($show_header) // display a table header
{
echo '<tr class="windowbg2">';

if($show_date) echo '<td align="right"> Date :</td>';
if($show_views) echo '<td align="center"> Views </td>';
if($show_author) echo '<td align="left"> Author </td>';

echo '<td align="left"> Article Title </td>';
}

foreach($article as $item)
{
if(empty($item['shortname'])) $item['shortname'] = $item['id']; // make shortname = id if it doesn't already exist (for JPDeni!)

if($use_theme_css)
{
echo '<tr class="windowbg' . ($row_class = $row_class == $css_row ? $css_row_alt : $css_row) . '">';
}
else
{
echo '<tr style="background: #' . ($row_class = $row_class == $css_row ? $css_row_alt : $css_row) . '">';
}

if($show_date)
{
echo '<td align="right"> ' . date("M j, Y", $item['date']) . ' :</td>';
}

if($show_views) echo '<td align="center"> (' . $item['views'] . ')' . '</td>';
if($show_author) echo '<td align="left"> (' . $item['author'] . ')</td>';

echo '<td align="left"> <a href="' . $scripturl . '?page=' . $item['shortname'] . '" target="' . $link_target . '">';
echo substr($item['subject'], 0, $link_width) . '</a>';

echo ' </td></tr>';
}

echo '</table>';
}
else // no articles = simple notice of nothing found; no table used
{
echo '<div class="titlebg">No Available Articles At This Time</div><hr />';
}

// start of navigation block
echo '<hr /><div class="titlebg" class="article_nav">';

if($start > 1) echo '<a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $prev_pg . '&cat=' . $category . '">Previous Page</a> | ';

echo $start + 1 . ' - ' . $next_pg;

if($next_pg < $total_rows) echo ' | <a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $next_pg . '&cat=' . $category . '">Next Page</a>';

echo ' | Total Articles : ' . $total_rows;

echo '</div>';

tpdb_free_result($query); // free up memory (nice to do)


Now my question -
Is there anyway to list the articles in alphabeticaly?

Thanks

The Wizard

IchBin

You keep saying it's a waste of time. What about our time? It's a waste of our time to have to ask people which versions of software they are running because the database queries are different, as well as the database row names, between the different versions of SMF and TP. It may appear as a waste of time to you, but it certainly saves us from having to ask you to do so.

You never said what you want to order it by alphabetically by. By the title? By the query title?

You should be able to change this section to get what you're asking.
ORDER BY date DESC

Change to "ORDER BY subject DESC"  if you want to sort it by the title. You can remove or leave DESC depending on which way you want it ordered alphabetically.

The Wizard

QuoteYou keep saying it's a waste of time. What about our time? It's a waste of our time to have to ask people which versions of software they are running because the database queries are different, as well as the database row names, between the different versions of SMF and TP. It may appear as a waste of time to you, but it certainly saves us from having to ask you to do so.

Sorry I just cut and pasted and should have left that out. I'm trully sorry if you were offended.
I would like to thank you for all the help you and your staff have provided. Without it I would have been lost.

Thanks

The Wizard

lurkalot

Quote from: The Wizard on November 11, 2010, 03:18:56 PM

I have changed your code a little for my use and so I'll post it here too -


Thanks for sharing.  O0  Would be handy if you edited your post above, and explained what changes you had made to the block.  Saves people having to try it just to find out what it does differently.   ;)

uniektekniek

Hey all, great block this one.. im having a slight problem with the "next page" links or sorting anything in general.. it just goes to a blank page.. sounds liek the same issue Rafferty was having on the first page of this thread, but it seems that was sorted out privately and theres not heaps of info on how to fix it... any ideas?? i've tried both php articles and blocks and the updated code for SMF2 posted by ichbin..



Link to my site: http://www.souldonsound.com/forum
SMF version: 2.0 RC3
TP version: 1.0 beta 5.2
Default Forum Language: English
Theme name and version:default
Browser Name and Version: FF 3.6
Mods installed: too many to list
Related Error messages: N/A

uniektekniek

nevermind.. just forgot to set the article its in.. all works great!

$page         = '';      // set to article # that this script is in

uniektekniek

so close to being perfect.. defining specific categories isnt working for me though.. is there something im missing in the below code? those 3 in the $cats_allowed variable are all i want.. i have made a seperate category for the article this code is in in an attempt to hide it from the 'No Specified Category' view.. but i cant seem to get rid of that category in the listings..



// Articles By Date
// September 24, 2008 | Tim Antley
// Version II (Already)

// Displays x Number Of Approved Articles Per Page / Sorted By Date (Latest To Oldest)
// Simple Pagination In Table Output Form
// Retrieve URL Variables To Parse

global $db_prefix, $scripturl, $context;

// script variables for customization
$show_date      = true;      // show date in table; true or false
$show_views      = true;      // show number of views for each article
$show_author   = false;      // show name of author in table; true or false
$show_header   = true;      // show table header w/ field values
$use_theme_css   = true;   // use theme CSS or set using colors below

// will use numeric values if $use_theme_css set to false
$css_row      = '999999';   // background color for first row; 999999 = light gray
$css_row_alt   = '666666'; // alternating row color; 666666 = dark gray

$link_width      = 60;      // max length of article name in table
$link_target   = '_blank';   // target for article link; _self = same window, _blank = new window
$link_color      = 'FF9900'; // hyperlink color; actually gets set in custom CSS block below

$limit         = 5;      // number of results to display per page
$cats_allowed   = array(1, 4, 10);   // valid category numbers; '0' = all categories; separate values with commas

$page         = '10';      // set to article # that this script is in

// no need to edit past this point! warranty void if modified...

$article      = array();
$limits         = array(5, 10, 20);
$row_class   = '';

// put URL variables into array
parse_str($_SERVER['QUERY_STRING'], $url_vars);

$start         = 0;      // set to 0; will check for URL value soon

// check for 'cat' and 'limit' values via GET first; use POST value instead, if set
if(!empty($_GET['cat']))   $category   = $_GET['cat'];   
if(isset($_POST['cat']))   $category   = $_POST['cat'];

if(isset($_GET['limit']))   $limit      = $_GET['limit'];
if(isset($_POST['limit']))   $limit      = $_POST['limit'];

if($limit < 0 || !in_array($limit, $limits)) $limit   = 10;

$url_link      = '';      // set to null

// build url string from array (exclude script variables)
foreach($url_vars as $key => $value)
{
   $key   = strtolower($key);   // restrict to lowercase
   
   if($key != 'page' && $key != 'start' && $key != 'cat' && $key != 'limit')
   {
      $url_link   .= $key . '=' . $value . '&';
   }   
}

$url_link      .= 'limit=' . $limit . '&';

// custom CSS block to set style
if(!$use_theme_css)
{
   echo '
   <style type="text/css">
   .article_nav a:link, a:hover
   {
   text-decoration: underline;
   color: #' . $link_color . ';
   }
   </style>';

   $css         = 'style=background: #';
}
else
{
   $css         = 'class="windowbg';
   $css_row      = '';
   $css_row_alt   = '2';
}

// crude way to get page name; $context SHOULD have this somewhere...
if(!empty($_GET['page']))   $page   = $_GET['page'];

// get starting point from URL and set to integer value; already defaulted to 0 if not set
if(!empty($_GET['start']))   $start   = intval($_GET['start']);

$query   = tpdb_query(
   "SELECT id, value1, type
   FROM {$db_prefix}tp_variables
   WHERE type = 'category'
   ", __FILE__, __LINE__);

$cats[0]   = array('id' => 0, 'cat_name' => 'No Specific Category'); // pre-populate generic category
   
while ($row = tpdb_fetch_assoc($query))   // populate category array
{
   $cats[]   = array(
            'id' => $row['id'],
            'cat_name' => $row['value1'],
            );
}

if($category != 0)
{
   $query      = tpdb_query(
    "SELECT *
   FROM {$db_prefix}tp_articles
   WHERE approved = 1
   AND category = {$category}
   ", __FILE__, __LINE__);
}
else
{
   $query      = tpdb_query(
    "SELECT *
   FROM {$db_prefix}tp_articles
   WHERE approved = 1
   ", __FILE__, __LINE__);
}
$total_rows   = tpdb_num_rows($query); // get number of articles approved

if($category != 0)
{
   $query      = tpdb_query(
    "SELECT id, value1
   FROM {$db_prefix}tp_variables
   WHERE id = {$category}
   ", __FILE__, __LINE__);

   $cat_desc   = mysql_fetch_array($query);
   $cat_desc   = $cat_desc['value1'];
   
   if(empty($cat_desc))   $cat_desc   = 'No Category Description In Database';

   $query      = tpdb_query(
    "SELECT id, date, subject, shortname, author, views, category
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
    AND category = {$category}
    ORDER BY date DESC
    LIMIT {$start}, {$limit}
    ", __FILE__, __LINE__);

}
else
{
   $cat_desc   = 'No Specified Category';
   
   $query      = tpdb_query(
    "SELECT id, date, subject, shortname, author, views, category
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
    ORDER BY date DESC
    LIMIT {$start}, {$limit}
    ", __FILE__, __LINE__);
}

while ($row = tpdb_fetch_assoc($query))   // place article info into $article array
{
   $article[]   = array(
               'id' => $row['id'],
               'date' => $row['date'],
               'subject' => $row['subject'],
               'shortname' => $row['shortname'],
               'author' => $row['author'],
               'views' => $row['views'],
               'category' => $row['category'],
               );
}

// display category select menu form w/ submit button
echo '<form name="article_menu" method="POST" action="' . $scripturl . '?' . $url_link . 'page=' . $page . '">';
echo '<select name="cat">';

foreach($cats as $item)
{
   echo '<option ' . ($item['id'] == $category ? 'selected ' : '') . 'value="' . $item['id'] . '">' . $item['cat_name'] . '</option>';
}
echo '</select>  ';

echo '<select name="limit">';
foreach($limits as $limit_sel)
{
   echo '<option ' . ($limit == $limit_sel ? 'selected ' : '') . 'value="' . $limit_sel . '">' . $limit_sel . '</option>';
}
echo '</select> Per Page ';

echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';

// display article table with info
if(count($article) > 0)
{

   // simple pagination routine; took entirely too long to get this right...
   if($start + $limit <= $total_rows)
   {
      $next_pg   = $start + $limit;
   }
   else
   {
      $next_pg   = $total_rows;
   }
   
   if($start - $limit >= 0)
   {
      $prev_pg   = $start - $limit;
   }
   else
   {
      $prev_pg   = 0;
   }

   // start of top navigation block
   echo '<hr /><div class="titlebg">' . $total_rows . ' Article' . ($total_rows > 1 ? 's' : '') . ' Available | ' . $cat_desc . '</div>';

   echo '<div class="titlebg" class="article_nav">';
   
   if($start > 1) echo '<a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $prev_pg . '&cat=' . $category . '">Previous Page</a> | ';
   
   echo $start + 1 . ' - ' . $next_pg;
   
   if($next_pg < $total_rows) echo ' | <a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $next_pg . '&cat=' . $category . '">Next Page</a>';
   
   echo '</div><hr />';

   echo '<table border="0" cellspacing="0" cellpadding="0">';
   
   if($show_header) // display a table header
   {
      echo '<tr class="windowbg2">';
     
      if($show_date)      echo '<td align="right">  Date :</td>';
      if($show_views)      echo '<td align="center">  Views  </td>';
      if($show_author)   echo '<td align="left">  Author  </td>';
     
      echo '<td align="left"> Article Title </td>';
   }
   
   foreach($article as $item)
   {
      if(empty($item['shortname'])) $item['shortname'] = $item['id']; // make shortname = id if it doesn't already exist (for JPDeni!)

      if($use_theme_css)
      {
         echo '<tr class="windowbg' . ($row_class   = $row_class == $css_row ? $css_row_alt : $css_row) . '">';
      }
      else
      {
         echo '<tr style="background: #' . ($row_class   = $row_class == $css_row ? $css_row_alt : $css_row) . '">';
      }
           
      if($show_date)
      {
         echo '<td align="right">  ' . date("M j, Y", $item['date']) . ' :</td>';
      }
     
      if($show_views)      echo '<td align="center"> (' . $item['views'] . ')' . '</td>';
      if($show_author)   echo '<td align="left"> (' . $item['author'] . ')</td>';
     
      echo '<td align="left"> <a href="' . $scripturl . '?page=' . $item['shortname'] . '" target="' . $link_target . '">';
      echo substr($item['subject'], 0, $link_width) . '</a>';
     
      echo ' </td></tr>';
   }
   
   echo '</table>';
}
else   // no articles = simple notice of nothing found; no table used
{
   echo '<div class="titlebg">No Available Articles At This Time</div><hr />';
}

// start of navigation block
echo '<hr /><div class="titlebg" class="article_nav">';

if($start > 1) echo '<a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $prev_pg . '&cat=' . $category . '">Previous Page</a> | ';

echo $start + 1 . ' - ' . $next_pg;

if($next_pg < $total_rows) echo ' | <a href="' . $scripturl . '?' . $url_link . 'page=' . $page . '&start=' . $next_pg . '&cat=' . $category . '">Next Page</a>';

echo ' | Total Articles : ' . $total_rows;

echo '</div>';

tpdb_free_result($query);   // free up memory (nice to do)


IchBin

It doesn't look to me like that $cats_allowed variable is even used. I don't have any where to test this at the moment. What are you trying to do? Are you only wanting certain categories available to display?