Jump to content

Announcements on a side box on website


RPS

Recommended Posts

I was able to get it working but taking from another method and coming up with this:

{php}
// truncate the text to only 65 chars, add ... to the end
function truncate($text) {
$text = substr($text,0,200);
$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
return $text;
}
include("support/dbconnect.php");
include("support/includes/functions.php");
$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,3"; 
$result = mysql_query($query);
while ($data = mysql_fetch_array($result)) {
$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = truncate($data['announcement']);
$date = fromMySQLDate($date);
echo'<div style="border:solid 1px #e8e8e8; padding:5px;background-color:#f7f7f7;">'.$date.' - <strong><a href="announcements.php?id='.$id.'">'.$title.'</a></strong><p class="sfont2">
'.$announcement.' <a href="announcements.php?id='.$id.'">...more</a></p></div><p>';
}
{/php}

 

 

Of course as stated - you will need to change appropriate URLs and HTML.

Link to comment
Share on other sites

  • 7 months later...

This sounds like a great solution however I tried it and got a blank page :(

 

I created a page called news.php

 

I posted this code:

 

-----------------------------------------------------------

 

<?

$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;

 

 

require '/home/trouble/public_html/billing/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'];

$announcement = truncate($data['announcement']);

$date = formatdate($date);

echo'<p><span>'.$date.'</span> - '.$announcement.' <a href="../billing/announcements.php?id='.$id.'"><img src="/images/more.gif" alt="more info" /></a></p>';

echo'<hr />';

$x=false;

}

if(!$x) echo '<p>News & announcements: <a href="../billing/announcements.php">view more</a></p>';

if($x) echo '<p>There are no new announcements.</p>';

?>

 

----------------------------------------------

 

Am I suppose to do something with this:

 

-----------------------------------------

require '/home/user/public_html/billing/configuration.php';

$link = mysql_connect($db_host,$db_username,$db_password);

mysql_select_db($db_name);

 

-----------------------

 

Am I suppose to change out the values to match my site??

 

/home/user/ - should that be something else?

 

$db_host

$db_username

$db_password

$db_name

 

Are those suppose to be something else?

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Is this working in WHMCS V3.8.2

I am attempting to use it but keep getting this error,

 

'.$date.' - '.$announcement.' more info'; echo''; $x=false; } if(!$x) echo '

News & announcements: view more
'; if($x) echo '

There are no new announcements.
'; ?> 

 

I have tried this several different ways and all end in failure. :|

What am I doing wrong ?

Could use some help with this as I would like to pull several WHMCS things into my main sites.

 

Thanks in advance for any help.

Link to comment
Share on other sites

I checked the changelog and don't see anything that would require significant DB changes.

 

I'm running this on 3.8.1 with no issues.

 

Try using the code here http://forum.whmcs.com/showpost.php?p=46028&postcount=13

 

If that doesn't work, check out the code Troy posted here: http://forum.whmcs.com/showpost.php?p=46011&postcount=10

 

Thanks RPS,

I will try these and get back with this thred to verify.

Link to comment
Share on other sites

I have to be doing something wrong,

I still get errors, and I have attempted all of these.

I'm starting to think I need to hire someone for this part.

 

.$date.' - '.$announcement.' more info'; echo''; $x=false; } if(!$x) echo '

News & announcements: view more
'; if($x) echo '

There are no new announcements.
'; ?> 

 

Either I am missing something or I am just in over my head, worked on this for over 2 hours now and still nothing works for me.

I should just stick to the basics and leave the rest to you pros. :oops:

Link to comment
Share on other sites

Are you saving this as a .php file?

 

:shock:

 

:oops:

 

Now I am really embarrassed.

 

Working now in V3.8.2 :-P

 

Not sure what I was thinking. I just kept editing in notepad++ and saving it.

 

Thanks for helping out an idiot like myself

Link to comment
Share on other sites

:shock:

 

:oops:

 

Now I am really embarrassed.

 

Working now in V3.8.2 :-P

 

Not sure what I was thinking. I just kept editing in notepad++ and saving it.

 

Thanks for helping out an idiot like myself

 

Don't worry we all make mistakes, trust me thats why everyone here is actively helping everyone else, sometimes it's just a second pair of eyes that does the trick.

Link to comment
Share on other sites

- What was the fix?

 

I forgot to put the title code in the "echo" that returns the announcement content.

 

- Check out http://www.php.net/date

 

Replace:

 

$date = formatdate($date);

 

With

 

$date = date("j F Y, g:i A", $date);

 

You can look at the PHP manual for specific customizations/examples.

 

Thanks for the code, I will test it shortly.

Link to comment
Share on other sites

- What was the fix?

 

 

- Check out http://www.php.net/date

 

Replace:

 

$date = formatdate($date);

 

With

 

$date = date("j F Y, g:i A", $date);

 

You can look at the PHP manual for specific customizations/examples.

 

What do I change? My code looks like this:

 

function formatdate($date) {

$year = substr ($date, 0, 4);

$month = substr ($date, 5, 2);

$day = substr ($date, 8, 2);

return $month.'/'.$day.'/'.$year;

}

Link to comment
Share on other sites

  • 2 weeks later...

I get the following error people

 

 '.$date.' - '.$announcement.' more info
'; echo''; $x=false; } if(!$x) echo '

News & announcements: view more
'; if($x) echo '

There are no new announcements.
'; 

 

Does any one have any idea why?

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