news poster

  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

this is about a news poster im making, Im stuck on an error.
this is just the display part.

Code: [ Select ]
<?php
$db = mysql_connect("dave90_nl_db", "dave90", "") or die ("Connection to database failed");
mysql_select_db("dave90_nl_db", $db);
$news_SQL = "SELECT * FROM news ORDER BY news_datetime DESC";
$news_result = mysql_query($news_SQL);
?>

<?php
//This part takes care of the message display
while($news = mysql_fetch_array($news_result)) {

?>
<P><br>
<center>
<table width="600" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<font face="arial">
<span style="font-size:12">
Posted on: <?php echo $news['news_datetime'] ?>
</span>
<br>
<span style="font-size:13">
<b><?php echo $news['news_header'] ?></b>
</span>
</font>
</td>
</tr>
<tr>
<td>
<?php
if(strlen($news['news_main']) > 220 {
$news['news_main'] = substr($news['news_main'], 0, 180) . " ... <a href="news.php?news_ID=" . $news['news_ID'] . ">more</a>";
}
?>
<br><font face="arial"><span style="font-size:13"><?php echo $news['news_main'] ?></span></font></td>
</tr>
</table>
</center>
<?php
}
mysql_close();
?>
  1. <?php
  2. $db = mysql_connect("dave90_nl_db", "dave90", "") or die ("Connection to database failed");
  3. mysql_select_db("dave90_nl_db", $db);
  4. $news_SQL = "SELECT * FROM news ORDER BY news_datetime DESC";
  5. $news_result = mysql_query($news_SQL);
  6. ?>
  7. <?php
  8. //This part takes care of the message display
  9. while($news = mysql_fetch_array($news_result)) {
  10. ?>
  11. <P><br>
  12. <center>
  13. <table width="600" border="0" cellspacing="0" cellpadding="0" align="center">
  14. <tr>
  15. <td>
  16. <font face="arial">
  17. <span style="font-size:12">
  18. Posted on: <?php echo $news['news_datetime'] ?>
  19. </span>
  20. <br>
  21. <span style="font-size:13">
  22. <b><?php echo $news['news_header'] ?></b>
  23. </span>
  24. </font>
  25. </td>
  26. </tr>
  27. <tr>
  28. <td>
  29. <?php
  30. if(strlen($news['news_main']) > 220 {
  31. $news['news_main'] = substr($news['news_main'], 0, 180) . " ... <a href="news.php?news_ID=" . $news['news_ID'] . ">more</a>";
  32. }
  33. ?>
  34. <br><font face="arial"><span style="font-size:13"><?php echo $news['news_main'] ?></span></font></td>
  35. </tr>
  36. </table>
  37. </center>
  38. <?php
  39. }
  40. mysql_close();
  41. ?>


is giving me an error on the line where if(strlen$news.... starts

its meant to that if the post has more than 220 characters, 180 are displayed, and the rest readable at a link. (set by the id of the post)

without that, just normally
Code: [ Select ]
echo $news['news_main']

works fine.

the same happening on when i try to change the time format, but ill leave things to this first.
thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Looks like you missed a closing parentheses after the 220 and before the opening bracket of the if clause.

Code: [ Select ]
if(strlen($news['news_main']) > 220 {

should be:
Code: [ Select ]
if(strlen($news['news_main']) > 220) {
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

damn, srry, i noticed another mistake btw too.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 162 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.