Jump to content

[SOLVED] Few questions


stelthius

Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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,

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.