Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: Looking for an announcement script

  1. #1
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default Looking for an announcement script

    I would like to find an announcement script that would allow users to type in text then hit submit and it post right below the whole text box. I would like it to last for 10 lines before the new entry is pushes it off. However I would also like to have a radio box that allows me to save an entry so it doesn't get deleted until I uncheck it.

    Can anyone help me?

  2. #2
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    sounds straight forward,

    Steps:

    1. Create a form like u said input box. on the same page, collect the values
    of the form by using $_POST.
    2. On the same page, create a table with width set to 100% and within the
    TD field use <?php if(isset($_POST['whtever_input_field_name'])){ echo
    $_POST['whtever_input_field_name'];}
    3. On the same page, on reception, write this value into the db with an auto
    incr field, and get the last insert id for manipulation "mysql_insert_id()".
    4. when new data comes in as and when user types, use a select query and
    limit it by 1 to get the latest entry and repeat step2 partially.

    are you looking for the entire code? or are you stuck in the process of writing one?

  3. The Following User Says Thank You to l_kris06 For This Useful Post:

    Dirt_Diver (01-07-2009)

  4. #3
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Well I don't know how to code it but I am still trying to learn php. I guess my first thoughts were where do I begin. I thought about creating a table in mysql that would hold the info but I wasn't sure if that's what I needed to do or not.

    What I do know is I have an html page already that I would insert the code into a table on the page. So the code can't relate to anything else other than itself and well the connection to the database of course. Oh and I would need it to auto run to the next line if it runs over but not have it count as 2 lines.

  5. #4
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Here is the page I just started for this little lesson.

    http://salmipropertyholdings.com/post.php

  6. #5
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    Mmm , so this 10 lines, you want the latest 10 posts to remain on top, with each post having a check box to it so that u can save those items and not hav them replaced with the newer ones?

    can be done.

  7. #6
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Yes, that would be perfect.

    Also one more think if it's not to much to ask.

    I would like it to post in this format.

    User inputs:
    Hi I'm Joe

    php output:
    Jan 6 2009 14:43 Hi I'm Joe
    -------------------------------------

    Also I just started working on the php and I copied what you put above and it's already working now I just need to tweek it to perfection.
    I also forgot to mention that I need it to stay on the page until it is deleted so if I close the page and open it from another location I can still see it, until someone else posts to it.

  8. #7
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    Ok, whatver you wanted is closed to completed, minus the checkbox and saving part. you can improvise, or maybe i can complete it tomorrow for you.

    create a db schema :

    +----------+------------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +----------+------------------+------+-----+---------+----------------+
    | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
    | username | varchar(300) | YES | | NULL | |
    | comment | varchar(3000) | YES | | NULL | |
    | time | varchar(30) | YES | | NULL | |
    | date | date | YES | | NULL | |
    +----------+------------------+------+-----+---------+----------------+



    PHP Code:
    <form id="form1" name="form1" method="post" action="">
      <label>
      <strong>Username</strong>: 
      <input type="text" name="user" id="user" />
      </label>
      <p><strong>Comments: </strong></p>
      <p>
        <label>
        <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
        </label>
      </p>
      <p>
        <label>
        <input type="submit" name="button" id="button" value="Submit" />
        </label>
      </p>
    </form>

    <?php

    include('dbconn.php');

    $date date("Y-m-d");
    $time date("g:i a");

    if(isset(
    $_POST['user'])){
    $username $_POST['user'];
    }

    if(isset(
    $_POST['comments'])){
    $comments $_POST['comments'];
    }

    if(
    $username != "" || $comments !=""){

    //insert this value
    $insert  "insert into comments(username,time,date,comment)values('$username','$time','$date','$comments');";
    $suc mysql_query($insert);
    $newID mysql_insert_id();
    }

    //fetch the latest 10 comments;

    $fetch "select * from comments order by date limit 10 ;";
    $suc mysql_query($fetch);
    ?>
    <table width="100%" style='font-size:13px;'>
    <?php 
    while($info mysql_fetch_array($suc)){ ?>
    <tr>
    <td>
    <?php 
    echo "<b>".$info['date']." | ".$info['time']."</b>&nbsp;&nbsp;".$info['comment'];
    ?>
    </tr>
    </td>
    <?php }?>
    </table>

  9. The Following User Says Thank You to l_kris06 For This Useful Post:

    Dirt_Diver (01-07-2009)

  10. #8
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    For whatever odd reason when I past in the php it throws off the entire page. The links swap sides and the table with the text fields in it disappear.

  11. #9
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Okay NM I figured all that out,

    First off let me say thank you a million times over your awesome.

    Next I have a few small adjustment favors to ask of you.

    1. I want to reverse the order in which the posts are displayed. Right now the latest post is on the bottom but I want to swap it to the top. How do I do this?

    Also I swapped the code around some, here is the new code as it sits.

    PHP Code:
    <?php
    include("dbconnect");

    $date date("Y-m-d");
    $time date("g:i a");


    if(isset(
    $_POST['user'])){
    $username $_POST['user'];
    }

    if(isset(
    $_POST['comments'])){
    $comments $_POST['comments'];
    }

    if(
    $username != "" || $comments !=""){

    //insert this value
    $insert  "insert into comments(username,time,date,comment)values('$username','$time','$date','$comments');";
    $suc mysql_query($insert);
    $newID mysql_insert_id();
    }

    //fetch the latest x amount of comments;

    $fetch "select * from comments order by date limit 20;";
    $suc mysql_query($fetch);
    ?>
    <?php 
    while($info mysql_fetch_array($suc)){ 
    ?>

    <?php 
    echo "<font color=\"#008000\">".$info['username']." -- ".$info['date']." @ ".$info['time']."</font>&nbsp;&nbsp;&nbsp;".$info['comment'];
    echo 
    "<br><br>";
    ?>

    <?php 
    }
    ?>
    Last edited by Dirt_Diver; 01-06-2009 at 10:14 PM.

  12. #10
    Join Date
    Dec 2008
    Location
    Fremont, CA
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default

    glad to have helped.

    To get the latest posts on the top, change

    Replace this:
    PHP Code:
    $fetch "select * from comments order by date limit 20;"
    with :

    PHP Code:
    $fetch "select * from comments order by date desc limit 20;"
    I see that you have removed the inline table for showing the comments, its always a good idea to use tables instead of break tags. when the comment characters increases, the table cell will expand, if thats your worry, you can always do a wrap. (wordwrap). Tables also come handy when u want alternate row highlight and things of that nature.

    Anyways, do you still want the option to prevent posts from moving away from the display list?

    Rgds,
    Kris
    Last edited by l_kris06; 01-07-2009 at 07:58 AM.

  13. The Following User Says Thank You to l_kris06 For This Useful Post:

    Dirt_Diver (01-07-2009)

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
  •