TinyPortal

Development => Block Codes => Topic started by: fangweile on January 17, 2012, 03:47:02 AM

Title: Help with Block code update
Post by: fangweile on January 17, 2012, 03:47:02 AM
I used the following blockscodes below in older version of tinyportal and using smf 1.1.4 and when i upgrade to the latest version TPRC3 and SMF 2, it doesnt work anymore.

The code below shows article intro in a block by most viewed.
global $db_prefix, $scripturl;
$query = db_query(
    "SELECT intro
     FROM {$db_prefix}tp_articles
     WHERE useintro = 1
     AND category=4
     ORDER BY views DESC
     LIMIT 1", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
  echo htmlspecialchars_decode($row['intro']);


Another is a block showing articles in creation date.
global $db_prefix, $scripturl;

$today = date('-m-d', strtotime("+13 hours"));
$query = db_query(
    "SELECT intro, id, date, subject, shortname
     FROM {$db_prefix}tp_articles
     WHERE FROM_UNIXTIME(date) LIKE '%" . $today . "%'
     AND category=1
     AND approved=1", __FILE__, __LINE__);
if(db_affected_rows() != 0)
{
  echo date ("l, F d, Y h:i:s a", strtotime("+13 hours"));
  echo '<br />';
  while ($row = mysql_fetch_assoc($query))
  {
echo htmlspecialchars_decode($row['intro']);
  }
}
else {
  echo date ("l, F d, Y h:i:s a", strtotime("+13 hours"));
  echo '<br />';
  echo 'No Birthdays Found in Database';
}




I think that the block codes above is need to be updated to work with TP1
THanks in advance.
Title: Re: Help with Block code update
Post by: IchBin on January 17, 2012, 04:53:35 PM
This should work.

global $smcFunc, $scripturl;
$query = $smcFunc['db_query']('', '
    SELECT intro
    FROM {db_prefix}tp_articles
    WHERE useintro = {int:intro}
    AND category = {int:cat}
    ORDER BY views DESC
    LIMIT 1',
array('intro' => 1, 'cat' => 4)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
echo htmlspecialchars_decode($row['intro']);



global $smcFunc, $scripturl;

$today = date('-m-d', strtotime("+13 hours"));
$query = $smcFunc['db_query']('', '
    SELECT intro, id, date, subject, shortname
    FROM {db_prefix}tp_articles
    WHERE FROM_UNIXTIME(date) LIKE "%' . $today . '%"
    AND category = {int:cat}
    AND approved = {int:approved}',
array('cat' => 1, 'approved' => 1)
);
if($smcFunc['db_affected_rows']() != 0)
{
echo date ("l, F d, Y h:i:s a", strtotime("+13 hours"));
echo '<br />';
while ($row = $smcFunc['db_fetch_assoc']($query))
{
echo htmlspecialchars_decode($row['intro']);
}
}
else
{
echo date ("l, F d, Y h:i:s a", strtotime("+13 hours"));
echo '<br /> No Birthdays Found in Database';
}
Title: Re: Help with Block code update
Post by: fangweile on January 18, 2012, 03:22:29 AM
THanks a lot IchBin, it works great.