Rasheed saeed Posted October 6, 2010 Share Posted October 6, 2010 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 Quote Link to comment Share on other sites More sharing options...
Equinox Posted October 6, 2010 Share Posted October 6, 2010 <?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 Quote Link to comment Share on other sites More sharing options...
Rasheed saeed Posted October 6, 2010 Author Share Posted October 6, 2010 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. :) Quote Link to comment Share on other sites More sharing options...
Equinox Posted October 6, 2010 Share Posted October 6, 2010 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>'; } Quote Link to comment Share on other sites More sharing options...
Rasheed saeed Posted October 6, 2010 Author Share Posted October 6, 2010 Ahh... Well thanks for the information there mate. That has kind of helped me.. +1 if I could :) Quote Link to comment Share on other sites More sharing options...
Joshua Posted October 8, 2010 Share Posted October 8, 2010 I could be wrong as EQ you know a bit more, but isnt assoc depreciating? Shouldn't you use fetch_array instead? or am i just reading wrong 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.