Jump to content
MakeWebGames

Announcement Help


Rasheed saeed

Recommended Posts

Hello,

Now a mate of mine wanted a new announcements, I said I would do a little re-code(that took me 2 mins) and I did, but something isn't coming out right. Now it's very basic because I cba with a hole load of shinanagins. But here the problem.

 

<?
   require_once('globals.php');

   $N_A = $ir['new_announcements'];
   $ID = $ir['userid'];

   $Q = $db->query('SELECT COUNT (*) FROM `announcements` ORDER BY `a_time` DESC');
   $R_Q = $db->fetch_row($Q);

  echo "<table width = '80%' cellspacing = '1' class = 'table'>
         <tr>
          <th>Time</th>
          <th>Announcement</th>
         </tr>";

 while ($R_Q)
{
 if ($N_A == 0)
{
     $NA = "";
}
 else
{
     $NA = "[b]<span style = 'color: red;'>New</span>[/b]
";
}

  echo "<tr>
         <td valign = 'top' width = '25%'>".date('F j Y, g:i:s a', $R_Q['a_time']).$NA."</td>
         <td valign = 'top' width = '75%'>".$R_Q['a_text']."</td>
        </tr>";
}

  echo '</table>';

 if ($N_A)
{
    $db->query("UPDATE `users` SET `new_announcements` 0 WHERE (`userid` = ".$ID.")");
}
 $h->enpage();
?>

 

Now. When I add in while the <td> continue to go on for a very long time for some reason, and when I remove it, it only shows me the announcement not all of them. If your getting me? If you could sort the problem out, great! But what would be better if you could explain why this is happening? I don't have a clue why, but mehh we all learn. Thanks :)

- Rasheed

Link to comment
Share on other sites

<?php
include(DIRNAME(__FILE__).'/globals.php');

   $Q = mysql_query('SELECT `a_time`, `a_text` FROM `announcements` ORDER BY `a_time` DESC');

  echo "<table width = '80%' cellspacing = '1' class = 'table'>
         <tr>
          <th>Time</th>
          <th>Announcement</th>
         </tr>";

 while ($Fetch = mysql_fetch_assoc($Q))
{
$NA = ($ir['new_announcements'] == 0) ? '' : '<span style = "color : #FF0000; font-weight : bold;">New</span>';

  echo "<tr>
         <td valign = 'top' width = '25%'>".date('F j Y, g:i:s a', $Fetch['a_time']).$NA."</td>
         <td valign = 'top' width = '75%'>".$Fetch['a_text']."</td>
        </tr>";
}

  echo '</table>';

if($NA) {
mysql_query("UPDATE `users` SET `new_announcements` = 0 WHERE `userid` = ".$_SESSION['userid']);
 $h->enpage();
}
?>

 

Try that

Link to comment
Share on other sites

Hmm.. Thanks bud. I haven't yet tried it since my server is working over, but could I ask 2 questions?

1: _assoc

What does this do? Does it work like _row?

2: ? '' :

Now i've never really got an Idea of what this is? Could you care to explain if you don't mind?

Sorry to be a pest, but it could hep me further on in the future and make me stop making posts. :)

Link to comment
Share on other sites

1. _assoc is the same as calling _array with MYSQL_ASSOC - using mysql_fetch_array() without specifying MYSQL_NUM or MYSQL_ASSOC returns a double array.

2. That is a ternary operator

What a done was the same as saying:

 

if($ir['new_announcement'] == 0) {
$Na = '';
} else {
$Na = '<span style = "color : #FF0000; font-weight : bold;">New</span>';
}
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.

×
×
  • Create New...