Jump to content

Announcements on a side box on website


RPS

Recommended Posts

Sorry RPS i have spent the last hour reading and changing the code as stated in this topic but still no luck.

 

the code i am using is here

 

http://www.cg-computers.co.uk/announcements.php

- Read post # 36. The guy has the exact same problem as you. He fixed it by using a php extension. If you did that, then there is probably something wrong with php.

 

Maybe try replacing that file with <? phpinfo(); ?> and see if anything comes up.

Link to comment
Share on other sites

  • 4 weeks later...

My Version:

 

<?
$x=1; // requested edit
// truncate the text to only 65 chars, add ... to the end
function truncate($text) {
   $text = substr($text,0,60);
   $text = substr($text,0,strrpos($text,' '));
   $text = $text."...";
   return $text;
}

// format the date to mm/dd/yyyy
function formatdate($date) {
   $year = substr ($date, 0, 4);
   $month = substr ($date, 5, 2);
   $day = substr ($date, 8, 2);
   return $month.'/'.$day.'/'.$year;
}

// limit the number of announcements to return
$limit = 2;

 echo('<p class="header">Announcements</p>');
require '/home/USERNAME/public_html/WHMCSLINK/configuration.php';
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);

$result = mysql_query("SELECT * FROM tblannouncements WHERE published='on' ORDER BY id DESC LIMIT ".$limit);
while($data = mysql_fetch_array ($result))
{
$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);
 echo("<p><font color=#cccccc>$date</font> - <b>$title</b> <br>$announcement</p>");
 echo('<a href="/whmcs/announcements.php?id='.$id.'">More Info</a><br>');
 echo('<hr />');
}
if(!$x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
if($x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
?> 

Link to comment
Share on other sites

My Version:

 

<?
$x=1; // requested edit
// truncate the text to only 65 chars, add ... to the end
function truncate($text) {
   $text = substr($text,0,60);
   $text = substr($text,0,strrpos($text,' '));
   $text = $text."...";
   return $text;
}

// format the date to mm/dd/yyyy
function formatdate($date) {
   $year = substr ($date, 0, 4);
   $month = substr ($date, 5, 2);
   $day = substr ($date, 8, 2);
   return $month.'/'.$day.'/'.$year;
}

// limit the number of announcements to return
$limit = 2;

 echo('<p class="header">Announcements</p>');
require '/home/USERNAME/public_html/WHMCSLINK/configuration.php';
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);

$result = mysql_query("SELECT * FROM tblannouncements WHERE published='on' ORDER BY id DESC LIMIT ".$limit);
while($data = mysql_fetch_array ($result))
{
$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);
 echo("<p><font color=#cccccc>$date</font> - <b>$title</b> <br>$announcement</p>");
 echo('<a href="/whmcs/announcements.php?id='.$id.'">More Info</a><br>');
 echo('<hr />');
}
if(!$x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
if($x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
?> 

 

This code has a problem! in echo's, you need to put your parameters like this :

". $title ."

So, this :

echo("<p><font color=#cccccc>$date</font> - <b>$title</b> <br>$announcement</p>");

Would just display $date, $title and $announcement. But if you change it to this :

echo("<p><font color=#cccccc>". $date ."</font> - <b>". $title ."</b> <br>". $announcement ."</p>");

It works completly. I have tested this and I wanted to help users that don't have PHP experience and are stuck on this. :-)

Hope it helps... :lol:

Link to comment
Share on other sites

What do you think of my code. The only thing is that it shows the WHOLE announcement... :P I do not know how to fix it...

 

Lol... if someone can please post it.

- Look at my first post:

 

// truncate the text to only 65 chars, add ... to the end
function truncate($text) {
   $text = substr($text,0,60);
   $text = substr($text,0,strrpos($text,' '));
   $text = $text."...";
   return $text;
} 

Link to comment
Share on other sites

Updated with 65 character Limit:

 

<?
$x=1; // requested edit
// truncate the text to only 65 chars, add ... to the end
function truncate($text) {
   $text = substr($text,0,60);
   $text = substr($text,0,strrpos($text,'   '));
   $text = $text."...";
   return $text;
}

// format the date to mm/dd/yyyy
function formatdate($date) {
   $year = substr ($date, 0, 4);
   $month = substr ($date, 5, 2);
   $day = substr ($date, 8, 2);
   return $month.'/'.$day.'/'.$year;
}

// limit the number of announcements to return
$limit = 2;

 echo('<p class="header">Announcements</p>');
require '/home/USERNAME/public_html/WHMCSLINK/configuration.php';
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);

$result = mysql_query("SELECT * FROM tblannouncements WHERE published='on' ORDER BY id DESC LIMIT ".$limit);
while($data = mysql_fetch_array ($result))
{
$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);
 echo("<p><font color=#cccccc> '.$date.' </font> - <b> '.$title.' </b> 
<br> '.$announcement.' </p>");
 echo('<a href="/whmcs/announcements.php?id='.$id.'">More Info</a><br>');
 echo('<hr />');
}
if(!$x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
if($x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
?> 

Link to comment
Share on other sites

  • 3 months later...

small modification if someone want to use mysqli instead mysql

 

<?PHP
$x=1;
// truncate the text to only 65 chars, add ... to the end
function truncate($text) {
   $text = substr($text,0,65);
   $text = substr($text,0,strrpos($text,' '));
   $text = $text."...";
   return $text;
}

// format the date to mm/dd/yyyy
function formatdate($date) {
   $year = substr ($date, 0, 4);
   $month = substr ($date, 5, 2);
   $day = substr ($date, 8, 2);
   return $year.'/'.$month.'/'.$day;
}

// limit the number of announcements to return
$limit = 2;


require '/home/user/public_html/whmcs/configuration.php';
$sql = new mysqli($db_host,$db_username,$db_password,$db_name);

$result = $sql->query("SELECT * FROM tblannouncements WHERE published='on' ORDER BY id DESC LIMIT ".$limit);

while ($row = $result->fetch_object())
{
$id = $row->id;
$date = $row->date;
$announcement = truncate($row->announcement);
$date = formatdate($date); 

   echo'<p><span>'.$date.'</span> - '.$announcement.' <a href="/whmcs/announcements.php?id='.$id.'"><img src="/images/more.gif" alt="more info" /></a></p>';
   echo'<hr />';
   $x=false;
}
$result->close();
$sql->close();


if(!$x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
if($x) echo '<p>News & Announcements: <a href="announcements.php">View More</a></p>';
?>

Link to comment
Share on other sites

  • 7 months later...

sorry to bring an old thread back to life, but this seems like a neat feature. I am just a bit confused how to do this - at first I thought you were just supposed to copy the code and put it somewhere inside you index.html and change the code around a bit...but this is wrong lol apparently it is supposed to be in its own .php file?

 

I just made its own .php file - now how do i get it to display on one of my webpages?! lol...sorry I am completely ignorant in how these things work!

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

Hello

how can i change unicod to utf-8 ?

becasue it show me

 

وزارت خزانه داری آمریکا تØ*ریم های اینترنتی علیه کاربران ایران سودان Ùˆ کوبا را لغو کرده Ùˆ از شرکت های ارایه دهنده Û

Link to comment
Share on other sites

That's about the only thing I miss with CMS are the super handy collections of extensions. I did away with Joomla on some new sites as I was tired of the security problems, but now I have to go and search out the old fashioned way for my plain ole html pages. But I have to say, (knock on wood) not one of them has been hacked from external sources as long as I've had them since 1998 ;)

 

thanks for the rss feedburner tip.

Link to comment
Share on other sites

I have a simple .html page and for obvious reasons don't want to convert to .php extensions. How would I go about including the announcements via WHMCS?

 

Thanks!

Meredith

 

Javascript? Sheesh.

 

Just configure your system to parse html files for PHP code - then follow the instructions previously given..

 

David

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...
  • 3 weeks later...
  • 9 months later...

I am wanting to display my announcements in my header banner image and want it to scroll through the announcements

I was looking for an rss feed to work with my site and whmcs to pull announcements from whmcs and display it in a certain area of my website the area is a small box so it is going to be limited to how much information is displayed so I was thinking that rss feeds would work better this way I have have it scroll through it or something

Edited by Buzz
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated