OSdata.com: holistic issues 

OSdata.com

example source code
newcelebrity.php

    Building a game — open source code This is the actual source code from a new web game. See the game at thissideofsanity.com and read how this was built starting at example code.

    This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.

    Copyright 2013 Milo (for software), Distribution and website handled by Strazbick.com

    Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

    This narrative uses anchor links so that you can follow the building of this software in chronological order. Go to software explanation to start reading. Go to thissideofsanity.com to see the working software.

Google

example source code
newcelebrity.php

    This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.

random celebrity
first pass

    Code to generate a random celebrity.

<?php

   require_once('./php/databasefunctions.php');

$result = ConnectCelebDataBase(0); /* located in /php/databasefunctions.php */

/* echo '<br>the result is *'.$result.'*'; */

?>

<h2 align="center">add to today’s slams</h2>
<p align="center"><span id="anotherarea"></span></p>

<?php

/* echo $_SERVER['SERVER_NAME']; /* TESTING */

/* PICK A CELEBRITY */
$chosennumber = rand(1,30); /* hard coded to number of celebrities */
$onelessnumber = $chosennumber - 1;


/* GATHER MOST HATED CELEBRITIES */
$celebritycount = 1; /* initializing for outputting rank numbers */

$query = 'SELECT celebnum,mainname,votecount FROM celebrity ORDER BY votecount DESC LIMIT 1';

$celeblistresult = mysql_query($query);

if ($celeblistresult)
  {

    $row = mysql_fetch_array($celeblistresult);

        /* note that I am mixing computation and display -- bad, bad me */
        $celebnum = $row["celebnum"];
        $celebname = $row["mainname"];
        $votecount = $row["votecount"];

        echo '<img src="./testpict/blankpicture.png" width="96" height="96" align="left">';

        echo '<h3 align="center">'.$celebname.'</h3><p align="center"><big><span id="celeb'.$celebnum.'">'.$votecount.'</span> slams<br><br><a href="javascript:void(0);" onclick="incrementvote('.$celebnum.');"><span style="color:red"><img src="./testpict/sledge.jpeg" width="26" height="19" border="0"></span></a></big></p>';

        $celebritycount = $celebritycount + 1; /* increment */

  } /* END IF have a valid SQL result object */

?>

show celebrity picture
second pass

    We make a few minor changes tyo detect if there is a celebrity picture and either display the celebrity picture or the default image.

    First we change the SQL. In reality I did this last because I simply forgot to make the change and had to debug why the code wasn’t working. This kind of detail is why you really want to be using object oriented code rather than procedural code.

        $query = 'SELECT celebnum,mainname,votecount,96picture FROM celebrity ORDER BY votecount DESC LIMIT '.$onelessnumber.',1';

    We fetch the location of the picture from the data base. If the database returns a NULL rsult, that will test as an empty string (relying on PHP language-specific mechanisms.

        $picture96 = $row["96picture"];

    We perform the test and emit the code for the appropriate situation (celebrity picture exists or use default image).

        if ($picture96 != '')
          echo '<img src="./cpict/'.$picture96.'" width="96" height="96" align="left">';
        else
          echo '<img src="./testpict/blankpicture.png" width="96" height="96" align="left">';

return to explanation of source code

celebrity info
third pass

    We make a minor change to allow for the more info button and info area.

?>

<p align="center"><a nohref onclick="downarrowaction(<?php echo $celebnum; ?>)" style="cursor:pointer;"><img src="./testpict/downarrow.png" width="9" height="8"></a></p>

<div id="infoarea">

</div><!--infoarea-->

<?php   ?>

return to explanation of source code


OSdata.com is used in more than 300 colleges and universities around the world

Find out how to get similar high web traffic and search engine placement.


OSdata.com is used in more than 300 colleges and universities around the world

Read details here.


    A web site on dozens of operating systems simply can’t be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.

    Click here for our privacy policy.


previous page next page
previous page next page

home page


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2013 Milo

    Last Updated: September 20, 2013

    Created: September 19, 2013

previous page next page
previous page next page