stelthius Posted December 15, 2008 Share Posted December 15, 2008 Ok guys i have a few questions to ask, as from previous posts im still learning Ok here is what im trying to to, im trying to make a broadcast messege system. in the admin page you have a text area you type in what you want to broadcast then hit update, it will then input the message you entered into mysql, on then on the website say main page for now it will show up (Broadcast message from admin : message here) but my trouble is as im so new to php/MySQL coding im unsure how to do this my main problem area is how to only show the message if there is a new one, Hope i explained it well enough for someone to understand what im trying to do, any help is appretiated. thanks Rick Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/ Share on other sites More sharing options...
stelthius Posted December 15, 2008 Author Share Posted December 15, 2008 This is how i think my table should be i maybe wrong but im not sure. Field Type Collation Attributes Null Default broadcastmessage blob BINARY Yes NULL Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716269 Share on other sites More sharing options...
gevans Posted December 15, 2008 Share Posted December 15, 2008 How much do you already have implemented? Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716270 Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 SELECT * FROM message_table WHERE x=x LIMIT 1 That should pull out the last one entered by default, replace the x=x if you had a where statement there before and of course the message_table part with your table name. If that does not work, try this one: SELECT * FROM message_table WHERE x=x order by ID desc LIMIT 1 where ID is the unique table identifier. (Primary Key) EDIT: As for the table structure, you should at least have a date and a primary key column broadcastid int NOT NULL auto_increment broadcastmessage blob null broadcasttime timestamp NOT NULL default CURRENT_TIMESTAMP (you may need to look this up) Then order it by timestamp or id, whichever. Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716272 Share on other sites More sharing options...
stelthius Posted December 15, 2008 Author Share Posted December 15, 2008 Right now not alot as i really am new to this but this is what i mocked up for the displaying of it, i havent added the functions to call the new message yet as i dont know how to do it this is why im asking for help <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php if($session->logged_in){ echo "<font face='Verdana' color='#FFFFFF' size='2'> Welcome back <b>$session->username</b>, } /* this is were i need to check for new messages in the DB */ echo '<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000"><tr><td><strong>Message from the administration:</strong> 'STRING TO DISPLAY NEW MESSAGE HERE'].'</td></tr></table><br>'; } } Rick, Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716273 Share on other sites More sharing options...
stelthius Posted December 15, 2008 Author Share Posted December 15, 2008 Sorry let me oppologise, I mean if there is no message in the DB i dont want the Alert bar to show at all if there is then i want it to show, and show the new alert.. Sorry im just finding it hard to explain something that i dont know how to do yet lol if that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716275 Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 <?php $res = mysql_query("SELECT * FROM message_table"); if (mysql_num_rows($res) > 0) { echo 'Display bar here'; } That is probably what you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716276 Share on other sites More sharing options...
gevans Posted December 15, 2008 Share Posted December 15, 2008 Firstly I'd add a table to my database. table: admin_message id INT auto_increment Primary Key message TEXT Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716278 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 ok so i create my table admin_message like this below, Field Type Collation Attributes Null Default Extra Action id int(100) No auto_increment I used 100 as sometimes there maybe a long message to display, So im assuming that this code, <?php $res = mysql_query("SELECT * FROM admin_message"); if (mysql_num_rows($res) > 0) { echo 'Display bar here'; } Whill then display the information in the table admin_message if there is any message in there at all ?. seems like there is something missing to me but im unsure im not the expert hehe Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716283 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 I'd advise you to go through some basic php tutorials, followed by some mysql ones, as it's obvious you dont understand standard syntax field1 - id INT auto_increment Primary Key field2 - message TEXT above are two fields not one INT stands for integer (numbers) Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716284 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Sorry, been at this for quite a while now im getting frustrated with it. I've corrected my blatent mistake, once again sorry about that its getting to me i guess lol Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716286 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 I just think you need to get a general understanding of php before you can undertake even the simplest task. Have a look around for some beginner tutorials. w3schools is a good starting resource Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716288 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 i have a understanding of php, i've just never done anything like this were i need to display something if there is new TEXT in the table, Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716289 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 Ok, how is your table now set up? do you have 2 fields? the `id` this should be an INT (you dont have to specify a length) make sure it is set to auto_increment and a Primary Key the second field - `message` set to TEXT again not needing a specified length Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716290 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Yes thats how i have my tables now, Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716294 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 ok, do you have an admin area set up?? And do you have a form ready to add a message? Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716295 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Yes i have a admin area already created, This is what im using for now till i can actually get this working then i will be tweaking it to suit, html form <form name="message" method="post" action="input.php"> <input type=text name=message> <form method="post" action=""> <input type="Submit" name="submit" value="Submit"> </form> and this is my input page <?php $db = mysql_connect("localhost","root","******") or die("Cannot connect to server"); mysql_select_db("login",$db) or die("Cannot find database"); $sql = mysql_query("INSERT INTO admin_message #this is as far as i have got with the insert function# ')") or die (mysql_error()); ?> Rick Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716299 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 <form name="message" method="post" action="input.php"> <input type=text name=message> <form method="post" action=""> <input type="Submit" name="submit" value="Submit"> </form> You've opened the form tab twice.... Change your form to <form name="message" method="post" action="input.php"> <input type="text" name="message"> <input type="Submit" name="submit" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716300 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Ok i re-did the input form and changed it to this as i know this works bettter for me <? $username="root"; $password="******"; $database="login"; $first=$_POST['message']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO admin_message VALUES ('','$first')"; mysql_query($query); mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716301 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 see if it works, try adding something, then check the database to see if its added Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716304 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 Yes it does work i just tried it out a few times, i added some text check it was there, then i added some more text and checked again and that was there also Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716305 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 ok, swap your home page code below.. <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php if($session->logged_in){ echo "<font face='Verdana' color='#FFFFFF' size='2'> Welcome back <b>$session->username</b>, } /* this is were i need to check for new messages in the DB */ echo '<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000"><tr><td><strong>Message from the administration:</strong> 'STRING TO DISPLAY NEW MESSAGE HERE'].'</td></tr></table><br>'; } } with this... <?php if($session->logged_in){ echo "<font face='Verdana' color='#FFFFFF' size='2'> Welcome back <b>$session->username</b>, } $username="root"; $password="******"; $database="login"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT message FROM admin_message ORDER BY id DESC LIMIT 1"; $result = mysql_query($query); $detail = mysql_fetch_array($result); echo '<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000"><tr><td><strong>Message from the administration:</strong>'.$detail['message'].'</td></tr></table><br>'; Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716307 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 well the message system works, now my problem is showing the alert bar only when there is a new message, also im greatfull for the help so far Rick Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716308 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 when you say 'only when there's a new message' how long is the message meant to last?? Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716310 Share on other sites More sharing options...
stelthius Posted December 16, 2008 Author Share Posted December 16, 2008 5 - 10 minutes max, i might just look into a way to turn the show or hide the alert box, im unsure which direction to take really Quote Link to comment https://forums.phpfreaks.com/topic/137123-solved-few-questions/#findComment-716311 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.