Jump to content

Complete NOOB -- Finally getting hands dirty - Dynamic message display needed


Recommended Posts

hello

 

i am a complete NOOB at trying to actually do my own php/mysql coding

 

:)

 

i have a genreal understanding of things and have been able to hack my way thru things... so far - but not for this

 

Now i need help

 

..............................

 

on my web site, i would like to display a welcome message that will change 5 times a day, based on time settings for given messages and have ability ot show suplimental display for day of the week after initial 'time slot'  message

 

...............................

 

i have table set that has these fields

 

................................................

`msg_id` int(32) NOT NULL auto_increment,

  `name` varchar(255) NOT NULL,

  `content` text NOT NULL,

  `start_time` varchar(255) NOT NULL,

  `end_time` varchar(255) NOT NULL,

  `week_day` text NOT NULL,

  `notes` varchar(1) NOT NULL,

  PRIMARY KEY  (`msg_id`)

 

.........................................................

 

 

this table  will hold data that have 5 messages for now, with titles 'morning, afternoon, late_afternoon, evening, and late' and content for message display to be shown

 

time for use - 'morning "name field" '

message to display "content field"

start_time "tells when to start to display message - server time"

end_time  "tells when to stop message - server time"

... in table for each message

 

plus add

 

day -"week_day field" with qualifer "Y" for additonal mesage display, to run concurrently with each of the 5 as above

 

sunday

monday

tuesday and so on for weeks worh of days display

 

........................

 

goal is to display this, so these messages run, based on server time -- and message start and end times, concurently,  and allow for added day after time slot message - we have Y on field notes for use day for qualifer...

 

morning message

afternoon message

late_afternoon message

evening message

late message

 

................................

 

how would such a display be assembled using php/mysql and actually run, displaying all as above?

 

..............................

 

many thanks

 

erv in minneapolis

 

 

 

 

 

 

ok...

 

so far have server time displaying for refrence -- but at noon hour, the 12 is missing?

 

what might be wrong here?

 

current server time is actually 12:13 pm --

 

this displays

 

current server time:

04/30/2009, 0:13 p.m.

 

  <?php

  $ct=date("m-d-Y-H-i");

  $str=explode("-",$ct);

  $cmo=$str[0];

  $cda=$str[1];

  $cye=$str[2];

  $cho=$str[3];

  $cmi=$str[4];

 

  echo "$cmo/$cda/$cye, ";

 

  if($cho==12 && $mi=="00") {

    echo $cho.":".$cmi;

  }

 

  elseif($cho > 11) {

    $cho=$cho - 12;

    echo $cho.":".$cmi." p.m.";

  }

 

  elseif($cho < 12) {

    echo $cho.":".$cmi." a.m.";

  }

  ?>

 

You have 3 cases:

1. if hour is 12 *AND* minute is 00. Though I don't know what's the difference between 0 and 00.

2. if hour is greater than 11, then you subtract 12 from it. So 12:13 is 0:13, I presume.

3. if hour is less than 12, display it.

 

So do you mean 12 is missing as in it's showing up as a 0?


  <?php
  $ct=date("m-d-Y-H-i");
  $str=explode("-",$ct);
  $cmo=$str[0];
  $cda=$str[1];
  $cye=$str[2];
  $cho=$str[3];
  $cmi=$str[4];

  echo "$cmo/$cda/$cye, ";

  if($cho==12 && $mi=="00") {
    echo $cho.":".$cmi;
  }

  elseif($cho > 12) {
    $cho=$cho - 12;
    echo $cho.":".$cmi." p.m.";
  }

  elseif($cho <= 12) {
    echo $cho.":".$cmi." a.m.";
  }
  ?>

?

ok...

 

thank you for the time snippets

 

:)

 

i am finally making some progress.....

 

but not really at the same time

 

in regards to the message display

 

i have this basic display working and day works

 

 

 

<?

$saturday = " content";

$afternoon = "content";

$late_afternoon = "Content $content ";

$evening = "Content";

$late = "Content ";

$morning = "content ";

$thursday = "  >>>>>> content -- $content <<<<<";

//No need to edit any further

 

//Get the current hour

$current_time = date(G);

//Get the current day

$current_day = date(W);

// Adjust time zone offset below. use $current_time == 1 && $h >=

$h = $h-2;

 

//12 p.m. - 330 p.m.

if ($current_time >= 12 && $current_time <= 14) {

echo $afternoon;

}

//12 a.m. - 7 a.m.

elseif ($current_time >= 15 && $current_time <= 18) {

echo $late_afternoon;

}

// 330 p.m. to 11 p.m.

elseif ($current_time >= 19 && $current_time <= 24) {

echo $evening;

}

//12 a.m. - 7 a.m.

elseif ($current_time >= 1 && $current_time <= 6) {

echo $late;

}

// 7 a.m. to 11 a.m.

elseif ($current_time >= 7 && $current_time <= 11) {

echo $morning;

}

 

//If its Friday, display a message

//if ($current_day = "Friday") {

//echo $friday;

//}

 

//If its Saturday, display a message

if ($current_day = "Thursday") {

echo $thursday;

}

 

?>

 

hpw do i go about converting this for use, to use data stored in the messages table?

 

`msg_id` int(32) NOT NULL auto_increment,

  `name` varchar(255) NOT NULL,

  `content` text NOT NULL,

  `start_time` varchar(255) NOT NULL,

  `end_time` varchar(255) NOT NULL,

  `week_day` text NOT NULL,

  `notes` varchar(1) NOT NULL,

  PRIMARY KEY  (`msg_id`)

 

any help to get me going in good direction will be greatly appreciated

 

erv

1 change the date fields to TIMESTAMP or DATE or TIME or DATETIME.

I prefer TIMESTAMP, just because it uses unixtime() functions, which ya can easily convert to yer needs.

But they all better than just using VARCHAR fields.

 

and its good habit to use fields types what they were meant for...

 

many thanks

 

but what i am asking....

 

how do i now use this or some new code to make use of data stored in db?

 

as we will have start and end times for each occasion...

 

also we may want an additioanl time display -- so this list has to be made on the fly, bases on data and qualifications in table -- (example friday set to 'Y')

 

this is what i am having a hard time with...

 

making the display page --

erv, learn to use


tags.

 

1. $content isn't defined on Line 4.

2. Are G and W constants? Pay a visit to php.net. date() function takes a string.

3. $h is also not defined when you call $h = $h - 2.

 

To use a DB is simple. Do you know how to connect to a database and run SQL statements?

-->To use a DB is simple. Do you know how to connect to a database and run SQL statements?

 

not really --

 

i need to start to learn how this is done...

 

everything is my site connects thru a central cfg file...

 

 

i looked for 'code' buttons in the post to forum -- i do not see them?

 

i can manually add them from now on

 

 

 

changed the 2 fields to TIMESTAMP

 

messiag id is way to keep trask of these?

 

there could be several different times of the day... who knows up to 10 if intended message display ia as cuch...

 

maybe we will want to show for an hour of the day, only that message 'Sale for this hour, order now and save, we give Coupon code , then that message expires

 

we do need days

we close early on saturday and sunday...

 

so we would like to show supplimental info for days of the week...

 

frinday - please ger your order in for the weekend... and so on...

 

i found a person that had set up something similar to show DJ's at a radio station - images when they were on line -- but that was a static script as well...

 

 

they had that set op on a 7 day calender - then showed time display based on >day then time of day...

 

this is the sort of think i wish for - but we will have messages...

 

 

 

But TIMESTAMP should tell everything. No need to add in days.

 

Set msg_id to AUTO_INCREMENT.

 

You'll probably need to learn how to connect to the DB and run SQLs.

<?php
// connect to DB.
$date = time();
$query = "SELECT * FROM table_name WHERE " . $date . " BETWEEN `start_time` AND `end_time`";
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {
    // display stuff here
}
// some other code here
?>

 

Again, read up on this so you're not exactly lost.

here is link to a script that did all of this manually for a radio station... http://www.dynamicdrive.com/forums/archive/index.php/t-15561.html

 

this is the sort of overall, fianal goal i have....

 

but to control it from my database with input for whatever hours of the day desired, and by day of week...

 

should i set this up for 'days' then have time messages for each day?

 

thursdays we have in house 2 for 1 sale in afternoons - drive home - stop in get 2 for one (we have a flower shop)

 

but for me, where day was thinking to to suppliment the current time displayed message... ...

 

???

 

am i maybe presenting this wrong in db table when i need seperate messages, by times, for each day of the week?

 

many thanks

 

 

ok.. i will review this....

 

 

now, how will i add these start and end times to db?

 

what i was able to edit, now is this showing the the field

 

0000-00-00 00:00:00

 

how do i get the start and end times for each message into db?

 

 

 

 

 

 

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.