jerett Posted June 26, 2008 Share Posted June 26, 2008 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. 0 Quote Link to comment Share on other sites More sharing options...
Mr.D Posted June 27, 2008 Share Posted June 27, 2008 Thanks. very Useful 0 Quote Link to comment Share on other sites More sharing options...
FrostByte Posted February 6, 2009 Share Posted February 6, 2009 Excellent little snippet. Thanks alot! 0 Quote Link to comment Share on other sites More sharing options...
zippohosting Posted February 10, 2009 Share Posted February 10, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
UK Host Direct Posted February 11, 2009 Share Posted February 11, 2009 this script works great for me on latest version 3.8.1 0 Quote Link to comment Share on other sites More sharing options...
buddy Posted February 23, 2009 Share Posted February 23, 2009 Hello, i have problem with $title. I can see just a number but not the really title of the news. Why that? Thanks for your help. 0 Quote Link to comment Share on other sites More sharing options...
buddy Posted February 23, 2009 Share Posted February 23, 2009 I have resolved. I wrote "$title = $date['title'];" instead of $title = $data['title']; 0 Quote Link to comment Share on other sites More sharing options...
Raze Posted April 7, 2009 Share Posted April 7, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted April 7, 2009 Author Share Posted April 7, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
Raze Posted April 7, 2009 Share Posted April 7, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
Raze Posted April 7, 2009 Share Posted April 7, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted April 7, 2009 Author Share Posted April 7, 2009 Are you saving this as a .php file? See the attached file, please be sure to open it and modify the line that reads: /home/user/public_html/whmcs/configuration.php The location needs to be correct. announcements.zip 0 Quote Link to comment Share on other sites More sharing options...
Raze Posted April 7, 2009 Share Posted April 7, 2009 Are you saving this as a .php file? Now I am really embarrassed. Working now in V3.8.2 Not sure what I was thinking. I just kept editing in notepad++ and saving it. Thanks for helping out an idiot like myself 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted April 7, 2009 Author Share Posted April 7, 2009 No worries, glad it's working now. 0 Quote Link to comment Share on other sites More sharing options...
moonsoft Posted April 8, 2009 Share Posted April 8, 2009 Now I am really embarrassed. Working now in V3.8.2 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. 0 Quote Link to comment Share on other sites More sharing options...
.amaZe Posted April 10, 2009 Share Posted April 10, 2009 I have resolved. I wrote "$title = $date['title'];" instead of $title = $data['title']; I tried your method, and both aren't working. I am running the latest version of WHMCS. 0 Quote Link to comment Share on other sites More sharing options...
.amaZe Posted April 11, 2009 Share Posted April 11, 2009 I tried your method, and both aren't working. I am running the latest version of WHMCS. I fixed this issue. But how do you get the date/time to display like this: "1 February 2009 | 2.32 PM" 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted April 12, 2009 Author Share Posted April 12, 2009 I fixed this issue. - What was the fix? But how do you get the date/time to display like this: - 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. 0 Quote Link to comment Share on other sites More sharing options...
.amaZe Posted April 13, 2009 Share Posted April 13, 2009 - 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. 0 Quote Link to comment Share on other sites More sharing options...
.amaZe Posted April 13, 2009 Share Posted April 13, 2009 - 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; } 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted April 13, 2009 Author Share Posted April 13, 2009 View the output of the date() function. You don't actually have to format the date. You can also (given the date), return only the month, year, or day. 0 Quote Link to comment Share on other sites More sharing options...
craigrg Posted April 23, 2009 Share Posted April 23, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted April 23, 2009 Author Share Posted April 23, 2009 Yes. Read this thread http://forum.whmcs.com/showthread.php?t=8142 for the answer 0 Quote Link to comment Share on other sites More sharing options...
craigrg Posted April 24, 2009 Share Posted April 24, 2009 Yes. Read this thread http://forum.whmcs.com/showthread.php?t=8142 for the answer 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 0 Quote Link to comment Share on other sites More sharing options...
druptech Posted April 24, 2009 Share Posted April 24, 2009 can we use on diffrent domain ? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.