SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Last replied date and time not same

    Hi there,

    I am currently doing a simple forum board but encountering a problem.
    The 'Last replied time and date' in my forum index page is not updated to the last replied message time and date inside that particular topic.

    Here's the code for the post reply
    PHP Code:
    <?php

    include "connect.php"//connection string

    print "<link rel='stylesheet' href='style.css' type='text/css'>";

    print 
    "<table class='maintables'>";

    print 
    "<tr class='headline'><td>Reply</td></tr>";

    print 
    "<tr class='maintables'><td>";

    if(isset(
    $_POST['submit']))

    {

       
    $name=$_POST['name'];

       
    $yourpost=$_POST['yourpost'];

       
    $subject=(isset($_POST['subject']))?$_POST['subject']:null;;

       
       
    $id=$_POST['id'];

       if(
    strlen($name)<1)

       {

          print 
    "You did not type in a name."//no name entered

       
    }

       else if(
    strlen($yourpost)<1)

       {

          print 
    "You did not type in a post."//no post entered

       
    }

       else

       {
          
    date_default_timezone_set('Asia/Brunei');
          
    $thedate=date("U"); //get unix timestamp

          
    $displaytime=date("F j, Y, h:i a");

          
    //we now strip HTML injections

          
    $subject=strip_tags($subject);

          
    $name=strip_tags($name);

          
    $yourpost=strip_tags($yourpost); 

          
    $insertpost="INSERT INTO elec_forum(author,title,post,showtime,realtime,lastposter, parentid) values('$name','$subject','$yourpost','$displaytime','$thedate','$name','$id')";

          
    mysql_query($insertpost) or die("Could not insert post"); //insert post

          
    $updatepost="Update elec_forum set numreplies=numreplies+'1', lastposter='$name', lastrepliedto='$thedate' where postid='$id'";

          
    mysql_query($updatepost) or die("Could not update post");
          print 
    "Message updated, go back to <A href='elec_message.php?id=$id'>Message</a>.";

       }



    }

    else

    {

       
    $id=$_GET['id'];

       print 
    "<form action='elec_reply.php' method='post'>";

       print 
    "<input type='hidden' name='id' value='$id'>";

       print 
    "Your name:<br>";

       print 
    "<input type='text' name='name' size='20'><br>";

       print 
    "Your message:<br>";

       print 
    "<textarea name='yourpost' rows='5' cols='40'></textarea><br>";

       print 
    "<input type='submit' name='submit' value='submit'></form>";



    }

    print 
    "</td></tr></table>";

    ?>
    Code for index page:
    PHP Code:
    <p ><h3 align="center">Department of Electronic Engineering</h3>
    <?php 

    include "connect.php"//mysql db connection here

    print "<link rel='stylesheet' href='style.css' type='text/css'>";

    print 
    "<A href='elec_post.php'>New Topic</a><br>";

    print 
    "<table class='maintable'>";

    print 
    "<tr class='headline'><td width=50%>Discussion Topic</td><td width=20%>Author</td><td>Replies</td><td>Last replied time</td></tr>";

    $getthreads="SELECT * from elec_forum where parentid='0' order by lastrepliedto DESC";

    $getthreads2=mysql_query($getthreads) or die("Could not get threads");


    while(
    $getthreads3=mysql_fetch_array($getthreads2))

    {

      
    $getthreads3['title']=strip_tags($getthreads3['title']);

      
    $getthreads3['author']=strip_tags($getthreads3['author']);
     
      print 
    "<tr class='mainrow'><td><a href='elec_message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td>
    $getthreads3[showtime]<br>Last post by <b>$getthreads3[lastposter]</b></td></tr>";

    }

    print 
    "</table>";



    ?>  

    <a href="forum.php?"><img src="image/button_back1.gif" border="0" align="right"/></a>
    The line of code in 'post reply' code
    PHP Code:
    $updatepost="Update elec_forum set numreplies=numreplies+'1', lastposter='$name', lastrepliedto='$thedate' where postid='$id'"
    give the correct 'last replied time and date.

    Line of code in index page-line 28
    PHP Code:
    $getthreads3[showtime
    give the time and date of the topic author. How to correct this so that I can know the last poster replied time and date in the index page?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    print "<tr class='mainrow'><td><a href='elec_message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td> 
    $getthreads3[showtime]<br>Last post by <b>$getthreads3[lastposter]</b></td></tr>"
    That will not work, PHP does not expand array elements inside quoted strings.

    This does work:
    PHP Code:
    $var "eek!";

    echo 
    "$var - a mouse!" 
    This does not work
    PHP Code:
    $a['var'] = "eek!";

    echo 
    "$a['var'] - a mouse!" 
    Whereas this does work
    PHP Code:
    $a['var'] = "eek!";

    echo 
    $a['var'] . " - a mouse!" 
    So you should be doing the likes of
    PHP Code:
    .... Last post by <b>" . $getthreads3['lastposter'] . "</b> .... 
    and so on, also note how I quote the array 'keys', you will likely be filling up your error log files with lots of unnecessary notices which will be a baIIache if you have to go looking for a real error.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •