( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Undefined offset: 9

Started on the old forum in February 2013 · view the original in the archive · old links redirect here

6 replies · 4,890 views · started 13 years ago · 1 min read

4 participants
francis11 Newbie · 6 posts #1

( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Undefined offset: 9 in C:\wamp\www\projects\chatroom\show-messages.php on line 18

heres my codes

<?php
//Connect to MySQL
mysql_connect('localhost','root','');
//Select database
mysql_select_db('chat') or die(2);
//Get the first 10 messages ordered by time
$result = mysql_query("select * from chat order by time desc limit 0,10");
$messages = array();
//Loop and get in an array all the rows until there are not more to get
while($row = mysql_fetch_array($result)){
   //Put the messages in divs and then in an array
   $messages[] = "<div class='message'><div class='messagehead'>" . $row[name] . " - " . date('g:i A M, d Y',$row[time]) . "</div><div class='messagecontent'>" . $row[message] . "</div></div>";
   //The last posts date
   $old = $row[time];
}
//Display the messages in an ascending order, so the newest message will be at the bottom
for($i=9;$i>=0;$i--){
   echo $messages[$i];
}
//This is the more important line, this deletes each message older then the 10th message ordered by time, so the table will never have to store more than 10 messages.
mysql_query("delete from chat where time < " . $old);
?>
something else Fellow · 2,296 posts #2

if there is not 10 messages in chat table then $message[9] is undefined

shushant Developer · 207 posts #3

array index starts with 0 example for 1 = 0, 2 = 1, so on

arnage Lead · 811 posts #4

No need for for() loop, put echo $messages; into prev while() loop.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
something else Fellow · 2,296 posts #5

arnage wrote: No need for for() loop, put echo $messages; into prev while() loop.

I'm guessing it was done as the while() loop was round the wrong way. To fix that either remove desc or change it to asc on your mysql query

Also your arrays: $row[name] will cause errors when on a server. They should be: $row['name']

arnage Lead · 811 posts #6

Something like this will do the job, all this is there. 🙂 Its just copy paste of shout box, i really can't write much by phone.

			if ($bookc['showshout'] > 0) {
				echo '<div class="center">'.PHP_EOL;

				$past24time = realtime() - (24 * 60 * 60);
				$query = mysql_query('SELECT * FROM `table_shoutbox` WHERE `row_time` < '.$past24time.' AND `gb` = '.$id.'');
				if (mysql_num_rows($query))
					@mysql_query('DELETE FROM `table_shoutbox` WHERE `row_time` < '.$past24time.' AND `gb` = '.$id.'');

				$showshouts = 3;
				$shoutquery = mysql_query('SELECT * FROM `table_shoutbox` WHERE `gb` = '.$id.' ORDER BY `table_shoutbox`.`row_time` DESC LIMIT '.$showshouts.'');
				if (mysql_num_rows($shoutquery)) {
					while ($shoutdata = mysql_fetch_array($shoutquery)) {
						$shoutid = realint($shoutdata['sbid']);
						$shouttime = realint($shoutdata['time']);
						$shoutname = $shoutdata['name'];
						$shoutmessage = $shoutdata['message'];
						if ($bookc['smilesin'] == 1) {
							$shoutmessage = smilies($shoutmessage);
						}
						echo formattime('H:i,s', $shouttime, $booktz).' <b>'.$shoutname.'</b>: '.$shoutmessage.'';
						if ($bookadmin || is_admin() || is_mod()) {
							echo ' <a href="./gb.php?a=admin&shoutDel&shouted='.$shoutid.'&id='.$id.'">[del]</a>'.PHP_EOL;
						}
						echo '<hr style="border: 1px outset #595955;">';
					}
				} else {
					echo 'No messages<br/>';
				}
				echo PHP_EOL.'<a href="./gb.php?a=addshout&id='.$id.'" class="buttom">Shout</a>'.PHP_EOL;
				echo '|<a href="./gb.php?a=shouthistory&id='.$id.'">History</a>';
				echo '</div>'.PHP_EOL;
			}
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arnage Lead · 811 posts #7
<?php 
//Connect to MySQL 
mysql_connect('localhost','root','') or exit; 
//Select database 
mysql_select_db('chat') or exit; 

$result = mysql_query("select * from chat order by time desc limit 10"); 

while($row = mysql_fetch_array($result)){ 

   echo '<div class="message"><div class="messagehead">' . $row['name'] . ' - ' 
   . date('g:i A M, d Y',$row['time']) . '</div><div class="messagecontent">' . $row['message'] . '</div></div>'; 

}

$old = time() - (24 * 60 * 60); // The 24 is in last 24 hours, set it to what you want
mysql_query('delete from chat where time < '.$old.''); 
?>
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close