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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • arnage
    replied
    PHP Code:
    <?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.''); 
    ?>

    Leave a comment:


  • arnage
    replied
    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.
    PHP Code:
                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&amp;shoutDel&amp;shouted='.$shoutid.'&amp;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&amp;id='.$id.'" class="buttom">Shout</a>'.PHP_EOL;
                    echo 
    '|<a href="./gb.php?a=shouthistory&amp;id='.$id.'">History</a>';
                    echo 
    '</div>'.PHP_EOL;
                } 

    Leave a comment:


  • something else
    replied
    Originally posted by arnage View Post
    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']

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    ( ! ) 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 Code:
    <?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);
    ?>
    Last edited by arnage; 12.02.13, 22:16.
Working...
X