Jump to content

php code help (greeting tree)


isuckat_php

Recommended Posts

Help is greatly appreciated. I am working on a code that needs to have the capabilities as this link:

http://athena.ecs.csus.edu/~cs010142/Greeting_tree.php

 

Exclude the background color and the blinking. I think there is away to set up arrays to make it do this but having difficulty. This is my code so far:

 

<?php

/*

Your brief description of this program which may include input, output, requirements, and your design highlights

*/

 

include_once("gt_functions.php");

 

# MAIN-PROGRAM

$title = "The Greeting Trees";

html_begin ($title, $title);

 

if ($submit)

{

$size=$_POST['size'];

$tree=$_POST['tree'];

$type=$_POST['type'];

 

if (($size == "")  || (!$tree))

{

  echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot

    to supply some information. </b></font><br>");

    }

    else if ((!ereg("[0-9]",$size))

    {

    echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict

    your input to only numbers.</b></font><br>");

}

else if (($size < "12")|| ($size > "24"))

{

echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Out of range</b></font><br>");

}

}

if else (!$type)

{

    echo "<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please select tree type. </b></font><br>");

 

}

 

else

{

//set up the data in a 2-dimensional array to mark the background

$A =array(array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"),

                array("0","0","0","0","0","0","0","0","0","0","0"));

 

//this array A is 11x11, therefore the center of a row is 5

 

$N = 11;

$center = 5;

 

//mark tree leaves

for ($i=0; $i < 5; $i++)

{

  for($j= ($center - $i); $j<= ($center + $i); $j++)

  {

    $A[$i+2][$j]= "*";

  }

}

 

//mark tree trunk

for ($i = 7; $i < 10; $i++)

{

$A[$i][$center] = "*";

}

 

//display elements of the array in colors of the tree type

 

for ($i=0; $i< $N; $i++)

{

 

  for($j=0; $j< $N; $j++)

{

  DisplayChar ($type, $A[$i][$j]);

  }

 

echo "<BR>";

}

 

DisplayGreeting($type);

 

}

}

 

//Form to collect user input: one of the 3  greeting tree types

?>

<FORM METHOD="post" ACTION="Greeting_tree.php">

<p>Please enter a tree size between 12 and 24:</p>

<input type="text" name="size" />

<p>Select tree type:</p>

<input type="radio" name="tree" value="Holiday"  /> Holiday

<input type="radio" name="tree" value="SacState" /> SacState

<input type="radio" name="tree" value="Suprise" /> Suprise

<br/>

<input type="submit" value="Display the tree" >

 

</FORM>

<? html_end () ?>

 

 

This is my gt_functions so far( it is not much):

 

<?php

# A collection of functions that will be included in Greeting_tree.php

 

function html_begin ($title, $header)

print ("<HTML>\n");

print ("<HEAD>\n");

if ($title)

print ("<TITLE>$title</TITLE>\n");

print ("</HEAD>\n");

print ("<BODY bgcolor=\"#FFFF9C\">\n");

if ($header)

print ("<H2>$header</H2>\n");

}

 

function html_end ()

{

print ("</BODY></HTML>\n");

}

 

function DisplayChar ($type, $char)

//display leave color when $char = "*" and background color when $char = "0" according to given tree type

{...}

 

function DisplayGreeting ($type)

//display greeting message according to given tree type

{...}

 

?>

 

Thank you for reading. Again help is much appreciated!

 

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.