Programmatically change my background graphic?

Discussion in 'HTML' started by Mike Silva, Dec 18, 2006.

  1. Mike Silva

    Mike Silva Guest

    Hi,

    I'm a programmer but not a web programmer. That hasn't stopped me from
    putting up a simple website, however. What I'd like to do is to be
    able to do is to change the graphic that forms the tiled background for
    the site, based on the calendar day. Something along the lines of

    if new_date
    todays_graphic = lookup_background_graphic( date )
    copy( todays_graphic TO generic_background_graphic_file )

    Very simple to imagine, but I have no idea how this might be done on a
    web server. Obviously my question is a just a particular instance of
    the general question how-do-I-run-code-on-my-website. So, how do I? I
    know there are various technologies to do so, so if you folks could
    just toss a few buzzwords my way I could go research things further.
    Thanks!
    Mike Silva, Dec 18, 2006
    #1
    1. Advertising

  2. Mike Silva wrote:
    > Very simple to imagine, but I have no idea how this might be done on a
    > web server. Obviously my question is a just a particular instance of
    > the general question how-do-I-run-code-on-my-website. So, how do I? I
    > know there are various technologies to do so, so if you folks could
    > just toss a few buzzwords my way I could go research things further.


    PHP, ASP
    Travis Newbury, Dec 18, 2006
    #2
    1. Advertising

  3. Mike Silva

    Mike Silva Guest

    Travis Newbury wrote:
    >
    > PHP, ASP


    Thanks. Now, how would one choose between them? My website is on a
    Linux server, if that matters.

    Mike
    Mike Silva, Dec 18, 2006
    #3
  4. Mike Silva wrote:

    > Travis Newbury wrote:
    >>
    >> PHP, ASP

    >
    > Thanks. Now, how would one choose between them? My website is on a
    > Linux server, if that matters.


    PHP.

    First thing that comes to mind is to use a modulo calculation based on
    the number of graphics you have stored in a "backgrounds" directory.

    --
    -bts
    -Motorcycles defy gravity; cars just suck
    Beauregard T. Shagnasty, Dec 18, 2006
    #4
  5. "Mike Silva" <> wrote in message
    news:...
    >
    > Travis Newbury wrote:
    >>
    >> PHP, ASP

    >
    > Thanks. Now, how would one choose between them? My website is on a
    > Linux server, if that matters.
    >


    PHP.

    +e
    The Eclectic Electric, Dec 18, 2006
    #5
  6. Mike Silva

    David Segall Guest

    "Mike Silva" <> wrote:

    >
    >Travis Newbury wrote:
    >>
    >> PHP, ASP

    >
    >Thanks. Now, how would one choose between them? My website is on a
    >Linux server, if that matters.

    PHP is a "write only" language and ASP almost requires a Microsoft
    server. Head for Java Server Faces if you want to follow Sun and
    Oracle. If you don't like Java as a server-side language you might
    want to look at Python. The other major choice for a server-side
    language is Perl which is extraordinarily powerful but even more
    difficult to read than PHP.
    David Segall, Dec 18, 2006
    #6
  7. Mike Silva wrote:
    > Travis Newbury wrote:
    >> PHP, ASP

    >
    > Thanks. Now, how would one choose between them? My website is on a
    > Linux server, if that matters.


    Well a very simple example in PHP for 1 - 31 backgrounds for each day of
    the month...

    <?php
    // Get the day of the month
    $dayOfTheMonth=date("j");
    // For background images 'bg1.jpg' to 'bg31.jpg'
    $background='pathToImages/bg' . $dayOfTheMonth . ".jpg";
    ?>

    Then insert it in the style element within the head...


    <style type="text/css">
    BODY { background-image url(<? echo $background; ?>); ... }
    ...

    Very, very simple example...

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Dec 18, 2006
    #7
  8. Mike Silva

    Mike Silva Guest

    David Segall wrote:

    > PHP is a "write only" language and ASP almost requires a Microsoft
    > server. Head for Java Server Faces if you want to follow Sun and
    > Oracle. If you don't like Java as a server-side language you might
    > want to look at Python. The other major choice for a server-side
    > language is Perl which is extraordinarily powerful but even more
    > difficult to read than PHP.


    Thanks to all who offered answers. Now, I've been poking around a bit
    in Adobe GoLive (the web editing program I'm using) and I don't see
    anything in the Help about PHP or ASP, but I do see stuff about
    JavaScript and a JavaScript editor. So, how does JavaScript fit in
    with my needs, if at all? Again, thanks to all for the help.
    Mike Silva, Dec 18, 2006
    #8
  9. Mike Silva wrote:

    > Thanks to all who offered answers. Now, I've been poking around a bit
    > in Adobe GoLive (the web editing program I'm using) and I don't see
    > anything in the Help about PHP or ASP, but I do see stuff about
    > JavaScript and a JavaScript editor. So, how does JavaScript fit in
    > with my needs, if at all? Again, thanks to all for the help.
    >

    IMHO I would avoid GoLive, HTML is not that difficult and PHP can be
    embedded in the HTML, and it is very simple. Hardest part of PHP is the
    countless core functions, just keep the function index handy!

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Dec 18, 2006
    #9
  10. Mike Silva

    Mike Silva Guest

    Jonathan N. Little wrote:

    > IMHO I would avoid GoLive, HTML is not that difficult and PHP can be
    > embedded in the HTML, and it is very simple. Hardest part of PHP is the
    > countless core functions, just keep the function index handy!


    Is this a comment about GoLive specifically, or about WYSIWYG-type web
    programming in general? I'd appreciate a little elaboration since I'm
    not terribly set in my ways as yet
    ..
    Mike Silva, Dec 18, 2006
    #10
  11. Mike Silva wrote:
    > Jonathan N. Little wrote:
    >
    >> IMHO I would avoid GoLive, HTML is not that difficult and PHP can be
    >> embedded in the HTML, and it is very simple. Hardest part of PHP is the
    >> countless core functions, just keep the function index handy!

    >
    > Is this a comment about GoLive specifically, or about WYSIWYG-type web
    > programming in general? I'd appreciate a little elaboration since I'm
    > not terribly set in my ways as yet
    > .
    >


    Basically WYSIWYG thing. Most folks tend to build vintage 97 markup with
    such. GoLive site tend to be image-slice sites. This is a
    generalizations, but a quick glance at the source tells all.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Dec 18, 2006
    #11
  12. Mike Silva

    Bergamot Guest

    Mike Silva wrote:
    > Jonathan N. Little wrote:
    >
    >> IMHO I would avoid GoLive

    >
    > Is this a comment about GoLive specifically


    I can't say what Mr Little meant, but I do know that GoLive can spit out
    some really ugly code. Quality is not one of its strong points, but then
    I'm not sure that it actually has any... ;)

    --
    Berg
    Bergamot, Dec 18, 2006
    #12
  13. Bergamot wrote:

    > Mike Silva wrote:
    >> Jonathan N. Little wrote:
    >>
    >>> IMHO I would avoid GoLive

    >>
    >> Is this a comment about GoLive specifically

    >
    > I can't say what Mr Little meant, but I do know that GoLive can spit
    > out some really ugly code. Quality is not one of its strong points,
    > but then I'm not sure that it actually has any... ;)


    I'll cast my vote for GoLive Ugly Code. I took over a site a few years
    ago that the original deezinger created with GoLive. Simply horrible.
    Nearly everything was an image. It's even worse than FrontPlague. Maybe
    worse than Publisher!

    I got the job to rewrite the GoLive site when I explained to the client
    just why he wasn't listed in any search engines.

    --
    -bts
    -Motorcycles defy gravity; cars just suck
    Beauregard T. Shagnasty, Dec 18, 2006
    #13
  14. Mike Silva

    joecool2000 Guest

    David Segall wrote:
    > PHP is a "write only" language and ASP almost requires a Microsoft
    > server.


    http://www.apache-asp.org/

    > The other major choice for a server-side
    > language is Perl which is extraordinarily powerful but even more
    > difficult to read than PHP.


    It's no more difficult to read than any other language.

    joecool
    joecool2000, Dec 18, 2006
    #14
  15. Beauregard T. Shagnasty wrote:
    > Bergamot wrote:
    >
    >> Mike Silva wrote:
    >>> Jonathan N. Little wrote:
    >>>
    >>>> IMHO I would avoid GoLive
    >>> Is this a comment about GoLive specifically

    >> I can't say what Mr Little meant, but I do know that GoLive can spit
    >> out some really ugly code. Quality is not one of its strong points,
    >> but then I'm not sure that it actually has any... ;)

    >
    > I'll cast my vote for GoLive Ugly Code. I took over a site a few years
    > ago that the original deezinger created with GoLive. Simply horrible.
    > Nearly everything was an image. It's even worse than FrontPlague. Maybe
    > worse than Publisher!
    >
    > I got the job to rewrite the GoLive site when I explained to the client
    > just why he wasn't listed in any search engines.
    >


    Yep, that is exactly what I meant. It has been my observation about
    GoLive, it tries to make a webpage from an image, I guess you could say
    Adobe PhotoShop-centric web design...

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Dec 19, 2006
    #15
  16. Mike Silva

    Neredbojias Guest

    To further the education of mankind, "Mike Silva" <>
    vouchsafed:

    >
    > David Segall wrote:
    >
    >> PHP is a "write only" language and ASP almost requires a Microsoft
    >> server. Head for Java Server Faces if you want to follow Sun and
    >> Oracle. If you don't like Java as a server-side language you might
    >> want to look at Python. The other major choice for a server-side
    >> language is Perl which is extraordinarily powerful but even more
    >> difficult to read than PHP.

    >
    > Thanks to all who offered answers. Now, I've been poking around a bit
    > in Adobe GoLive (the web editing program I'm using) and I don't see
    > anything in the Help about PHP or ASP, but I do see stuff about
    > JavaScript and a JavaScript editor. So, how does JavaScript fit in
    > with my needs, if at all? Again, thanks to all for the help.


    For something simple like a background image, I probably would use
    javascript if there was no other php in the page. So the non-j/s bloke
    (and blokess) get the same image, big deal... 'Course, you kinda have to
    know javascript, but it's simple code based upon the Date() function.
    There must be examples out there in never-never virtual land somewhere.
    But if you get stuck, in a couple o' days I'll make you one myself.

    I generally prefer javascript to server-side scripts because unless you
    have a trs 80-model one, it's faster. But...the user can turn it off and
    if he/she/it scours dubious websites, there is good reason to do so.

    --
    Neredbojias
    Infinity has its limits.
    Neredbojias, Dec 19, 2006
    #16
  17. Mike Silva

    Toby Inkster Guest

    Toby Inkster, Dec 19, 2006
    #17
  18. Mike Silva

    David Segall Guest

    Toby Inkster <> wrote:

    >David Segall wrote:
    >
    >> PHP is a "write only" language

    >
    >Yours might be.

    It might have been but because I could not read anyone else's I have
    never written any. I chose Servlets (Java) instead.

    I do not deny that the programmer is the most significant factor in
    the readability of a program but would you really promote PHP as a
    language because it is easy to read?
    David Segall, Dec 19, 2006
    #18
  19. Mike Silva

    Toby Inkster Guest

    David Segall wrote:

    > I do not deny that the programmer is the most significant factor in
    > the readability of a program but would you really promote PHP as a
    > language because it is easy to read?


    I certainly wouldn't advise *against* it because of legibility concerns.

    Any language that supports comments (not all do) and allows the programmer
    to choose variable and function identifiers using arbitrary alphanumeric
    names (again, not all do) can be made very readable simply by using these
    facilities. With most common programming languages, you can easily
    clarify your code by having a policy that includes choosing sensible,
    readable function and variable names, using indentation and plenty of
    white space, adding liberal comments, keeping line lengths down to a
    reasonable length, keeping function sizes down to 20 or so lines (longer
    functions can often be split into two or more functions). Yes, even Perl!

    For example, consider the following two (untested) PHP objects which are
    exactly equivalent except identifier names, comments and formatting.

    <?php

    /* Person class, which stores customer data. */
    class Person
    {
    /* Variables to store saved data. */
    var $data = array(); // Data from database.
    var $dirty = FALSE; // Dirty flag.
    var $id = -1; // Customer ID

    /* [Person] = new Person ([mixed optional] customer)
    * Takes a customer ID number as an argument. If ID is
    * not supplied, or customer ID is 'NEW', then creates
    * a new person.
    */
    function Person ($customer='NEW')
    {
    // We need the database connection.
    global $db_connection;

    // For existing customers with a valid-looking ID...
    if ($customer != 'NEW' && is_integer($customer))
    {
    // Construct the correct query and run it
    $select = "SELECT customer_id, name, address, postcode "
    . "FROM customers "
    . "WHERE customer_id={$customer};";
    $resultset = pg_query($db_connection, $select);

    // Check we have a result and store it.
    if ($row = pg_fetch_assoc($resultset))
    {
    $this->id = $customer;
    $this->dirty = FALSE;

    $this->data['name'] = $row['name'];
    $this->data['address'] = $row['address'];
    $this->data['postcode'] = $row['postcode'];
    }
    } // end if ($customer != 'NEW' && is_integer($customer))

    // Check to see if we've actually (by now) managed to read
    // an existing customer. If we haven't then this is a new
    // customer, so data cannot already be in database. Thus
    // data is by definition "dirty".
    if ($this->id == -1)
    $this->dirty = TRUE;

    return $this;
    }

    /* [boolean] = save ([void])
    * Saves data into the database. Takes no parameters,
    * returns TRUE iff successful.
    */
    function save ()
    {
    // Firstly check to make sure we actually have anything
    // worth saving. If not, then bail out and pretend that
    // we actually saved the data by returning TRUE.
    if (!$this->dirty)
    return TRUE;

    // We will certainly need this then!
    global $db_connection;

    // Which data do we want to save?
    $save_data = array(
    'name' => $this->data['name'],
    'address' => $this->data['address'],
    'postcode' => $this->data['postcode']
    );

    // If the customer is new (customer ID will be -1)
    if ($this->id == -1)
    {
    // We'll need to insert into the database.
    // The customer ID will be filled in by the DB engine.
    $result = pg_insert($db_connection, 'customers', $save_data);
    }

    // Otherwise the customer must be an existing one
    else
    {
    // Update database with new data.
    $result = pg_update($db_connection, 'customers', $save_data,
    array('id'=>$this->id));
    }

    // Return success
    return $result;
    }

    /* [mixed] = attribute ([string] attribute, [mixed, optional] value)
    * Gets or sets the attribute named in the first parameter.
    * If a second parameter is provided, will set the attribute to
    * that value. Will always return the value of the attribute.
    */
    function attribute ($attribute, $value=NULL)
    {
    // If the value is not NULL, then set the attribute
    if ($value===NULL)
    {
    $this->data[$attribute] = $value; // change attribute
    $this->dirty = TRUE; // and mark object as dirty
    }

    // Always return the value
    return $this->data[$attribute];
    }
    }

    ?>

    and now the unreadable version:

    <?php

    class Person
    {
    var $data = array();
    var $dirty = 0;
    var $id = -1;
    function Person ($cid='NEW')
    {
    global $DB;
    if ($cid != 'NEW' && is_integer($cid)) {
    $q= "SELECT customer_id, name, address, postcode FROM customers WHERE customer_id={$cid};";
    $r = pg_query($DB, $q);
    if ($X = pg_fetch_array($r)) {
    $this->id = $cid;
    $this->dirty = 0;
    $this->data['name']= $X[1];
    $this->data['address']=$X[2];
    $this->data['postcode'] = $X[3];
    }
    }
    if ($this->id == -1) $this->dirty = TRUE;
    return $this;
    }
    function save_customer_2_database(){
    if(!$this->dirty){return 1;}
    global $DB;
    $myarray= array('name' => $this->data['name'],
    'address' => $this->data['address'],
    'postcode' => $this->data['postcode']);
    if ($this->id == -1)
    return pg_insert($DB, 'customers', $myarray);
    return pg_update($DB, 'customers', $myarray, array('id'=>$this->id));
    }
    function GetAttribute ($a, $v=NULL) {
    if ($v===NULL)
    {
    $this->data[$a] = $v;
    $this->dirty =1;}
    return $this->data[$a];
    }
    }
    ?>

    What a difference!

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Dec 19, 2006
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    6
    Views:
    531
  2. Jim Jones

    Q. Background graphic width ?

    Jim Jones, Apr 14, 2004, in forum: HTML
    Replies:
    4
    Views:
    351
    ollimax
    Apr 15, 2004
  3. VanReenenc
    Replies:
    1
    Views:
    1,097
    VanReenenc
    Sep 1, 2006
  4. 50 SOMETHING GAL
    Replies:
    3
    Views:
    383
  5. Dax
    Replies:
    0
    Views:
    90
Loading...

Share This Page