Topic: Code : Listing news in the block with newimage..
viking
avatar
Noob
Noob
Posts: 12

Posted:
Jun 12, 2006

Hi..

Yes it`s me again, asking about script..

This script for listing the news in the block..

Code
  1. $dbconn =& pnDBGetConn(true);
  2. $pntable =& pnDBGetTables();
  3. $query="SELECT pn_sid, pn_title, pn_hometext, pn_time FROM $pntable[stories]
  4. where pn_catid=1 ORDER BY pn_time DESC LIMIT 5";
  5.  
  6. $result=mysql_query($query);
  7. while (list($sid, $title, $headlinetitle, $time) = mysql_fetch_row($result)) {
  8. if(strlen($title) > 40)
  9. {$title = substr($title,0,30);
  10. $title .= "...";}
  11.  
  12. $content .= "   <strong>&middot</strong> <a href=\"index.php?name=News&file=article&sid=$sid\">$title</a><br>";}
  13.  
  14. echo $content;


And I get this (xstories block)to include image for new today & week.. And dont know how to combine this two script..

Code
  1. $xtime= ml_ftime(_DATEBRIEF,$time);
  2.  
  3.     $newimage = "images/global/blank.gif";
  4.     if ($time >= strtotime("-7 DAY")) {
  5.     $newimage = "images/global/new_week.gif"; }
  6.     if ($time >= strtotime("-3 DAY")) {
  7.     $newimage = "images/global/new_3day.gif"; }
  8.     if ($time >= strtotime("-1 DAY")) {
  9.     $newimage = "images/global/new_day.gif"; }
  10.    
  11.     if ($vars['usenewimage'] == 1) {
  12.     $newimage = "images/blank.gif";}


Just asking, maybe someone could help me here.. or give me another solution ?.. :D

Thanks..
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Jun 13, 2006

You want a block with that you you already have a working block and want to add the image ?

Insert the second part between line 10 and 12 and add an img tag to the content.

Code
  1. $content .= "   <strong>·</strong> <a href=\"index.php?name=News&file=article&sid=$sid\">$title</a> <img src=\"$newimage\" title=\"image\" /><br>";



Chestnut ! Cool
Site Admin
viking
avatar
Noob
Noob
Posts: 12

Posted:
Jun 15, 2006

Thanks.. but forget about it..

I back to use script that U give me last year.. and make some change.. but `newimage' still not show correctly.. it just show blank.gif even for today added News..

Here`s the code..

Code
  1. $cat = 28;
  2. $dalimit = 5;
  3.  
  4. list($dbconn) = pnDBGetConn();
  5. $pntable = pnDBGetTables();
  6. $query = "SELECT pn_sid, pn_title, pn_hometext, pn_time FROM $pntable[stories]
  7.         WHERE  pn_catid='".pnVarPrepForStore($cat)."'
  8.         ORDER BY pn_time DESC LIMIT ".pnVarPrepForStore($dalimit);
  9.  
  10. $result = $dbconn->Execute($query);
  11. while(list($sid, $headlinetitle, $story, $stime) = $result->fields) {
  12.    $result->MoveNext();
  13.    $content .= "
  14. <img src=\"images/global/dot.gif\"> <b>";
  15.    $content .= pnVarPrepForDisplay($headlinetitle);
  16.    $content .= "</b> ";
  17.  
  18.     if ($time >= strtotime("-3 DAY")) {
  19.     $newimage = "images/global/new1.gif";
  20.     } else {
  21.     $newimage = "images/global/blank.gif";
  22.     }
  23.  
  24. $content .= "<img src=\"".$newimage."\">";
  25.    
  26. if(strlen($story) > 110)
  27. {$story = substr($story,0,110);
  28. $story .= "...";}     
  29.  
  30.     $content .= "
  31. <a href=\"modules.php?op=modload&name=News&file=article&sid=".pnVarPrepForDisplay($sid)."\">";
  32.     $content .= $story;
  33.     $content .= "</a>";
  34.  
  35. }
  36. printf($content);




edited by: viking, Jun 15, 2006 - 02:27 AM
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Jun 18, 2006

Problem is that you are comparing a date in readable format against a UNIX timestamp.

Code
  1. if (date("Y-m-d H:i:s", $time) >= strtotime("-3 DAY")) {


Might work better. icon_wink

Chestnut ! Cool
Site Admin
viking
avatar
Noob
Noob
Posts: 12

Posted:
Jun 19, 2006

I`m really appreciate you help.. but still can make it happend.. icon_frown icon_frown

The last code ;
Code
  1. <?
  2.  
  3. $cat = 28;
  4. $dalimit = 5;
  5. list($dbconn) = pnDBGetConn();
  6. $pntable = pnDBGetTables();
  7. $query = "SELECT pn_sid, pn_title, pn_hometext, pn_time FROM $pntable[stories]
  8.         WHERE  pn_catid='".pnVarPrepForStore($cat)."'
  9.         ORDER BY pn_time DESC LIMIT ".pnVarPrepForStore($dalimit);
  10.  
  11. $result = $dbconn->Execute($query);
  12. while(list($sid, $headlinetitle, $story, $stime) = $result->fields) {
  13.   $result->MoveNext();
  14.  
  15. $content .= "<br><img src=\"images/global/dot.gif\"> <b>";
  16. $content .= pnVarPrepForDisplay($headlinetitle);
  17. $content .= "</b> ";
  18.  
  19.     if (date("Y-m-d H:i:s", $time) >= strtotime("-3 DAY")) {
  20.     $newimage = "images/global/new_day.gif";
  21.     } else {
  22.     $newimage = "images/global/blank.gif";
  23.     }
  24.  
  25. $content .= "<img src=\"".$newimage."\">";
  26.    
  27. if(strlen($story) > 110)
  28. {$story = substr($story,0,110);
  29. $story .= "...";}
  30.  
  31. $content .= "<br><a href=\"modules.php?op=modload&name=News&file=article&sid=".pnVarPrepForDisplay($sid)."\">";
  32. $content .= $story;
  33. $content .= "</a>";
  34.  
  35. }
  36. printf($content);
  37. }
  38.  
  39. ?>
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Jun 19, 2006

$stime intead of $time...

My bad, your first post was using "time" but not the others...



Chestnut ! Cool
Site Admin
viking
avatar
Noob
Noob
Posts: 12

Posted:
Jun 19, 2006

Fix it.. but still with no luck.. icon_frown
It`s still just showing blank.gif for all news in the list..
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Jun 21, 2006

Yea well....... another one of my bad...

Code
  1. if (date("Y-m-d H:i:s", $stime) >= date("Y-m-d H:i:s", strtotime("-3 DAY"))) {


That should be it I think...

Chestnut ! Cool
Site Admin
viking
avatar
Noob
Noob
Posts: 12

Posted:
Jun 25, 2006

Thanks lot Chestnut for your help..
But sad to say that it`s also give the same result.. icon_frown

Last code try ::

Code
  1. $cat = 4;
  2. $dalimit = 4;
  3.  
  4. list($dbconn) = pnDBGetConn();
  5. $pntable = pnDBGetTables();
  6. $query = "SELECT pn_sid, pn_title, pn_hometext, pn_informant, pn_time FROM $pntable[stories]
  7.     WHERE  pn_catid='".pnVarPrepForStore($cat)."'
  8.         ORDER BY pn_time DESC LIMIT ".pnVarPrepForStore($dalimit);
  9.  
  10. $result = $dbconn->Execute($query);
  11. while(list($sid, $headlinetitle, $story, $info, $stime) = $result->fields) {
  12.    $result->MoveNext();
  13.  
  14.     if (date("Y-m-d H:i:s", $stime) >= date("Y-m-d H:i:s", strtotime("-3 DAY"))) {
  15.     $newimage = "images/global/new1.gif";
  16.     } else {
  17.     $newimage = "images/global/dot.gif";
  18.     }
  19.  
  20.  $content .= "<br><img src=\"".$newimage."\"> ";
  21.  
  22.   $content .= "<a href=\"modules.php?op=modload&name=News&file=article&sid=".pnVarPrepForDisplay($sid)."\">";
  23.    $content .= "<b>".pnVarPrepForDisplay($headlinetitle)."</b></a>";
  24.    
  25. if(strlen($story) > 110)
  26. {$story = substr($story,0,110);
  27. $story .= "...";}     
  28.  
  29.     $content .= "<br>$story";
  30.  
  31. }
  32. printf($content);
  33. }
Chestnut
avatar
Site Admin
Posts: 1320

Posted:
Jun 27, 2006

I'll take one last attempt... The stime is already in a YYYY-MM-DD HH:MM:SS so there is no need to put it in a date function...

so the final if should be :

Code
  1. if ($stime >= date("Y-m-d H:i:s", strtotime("-3 DAY"))) {


icon_wink

Chestnut ! Cool
Site Admin
viking
avatar
Noob
Noob
Posts: 12

Posted:
Jul 02, 2006

Yeah.. !! Congratulation..

* To FRANCE to reach semi-final..
* to Chestnut to make this script work !!

icon_biggrin Thanks lot... icon_biggrin