Create a php page that will process the order using an array and display the results on another page.

your html form must look like blown:
———————————————————————————————————————————

<form action=”hardware_order.php” method=”post”>
<fieldset>
<legend>Order Form</legend>
<p><label for=”user”> Name</label> <input type=”text” name=”name” id=”user” /></p>
<p><strong>Select Some Products:</strong> <br>
<select name=”products[]” multiple>
<option value=”Sonic Screwdriver”>Sonic Screwdriver</option>
<option value=”Hammer”>Hammer</option>
<option value=”Drill”>Drill</option>
<option value=”Spanner”>Spanner</option>
</select>
<p><input type=”submit” name=”submit” value=”send”></p>
</fieldset>
</form>

————————————————————————————————————————
there are two ways can proceed this: one is :
————————————————————————————————————————-
<?php
$name =trim($_POST[‘name’]);
if(empty($_POST[‘products’])||empty($name))
{
echo “nothing has been selected”;
}
else
{
echo “Thanks “.$name.” your select products is “;

foreach($_POST[‘products’] as $o)
{
echo $o.”<br/>”;
}
}
?>
————————————————————————————————————————–
another ways is teacher’s answers:
———————————————————————————————————————————<?php
$name =trim($_POST[‘name’]);
if (!empty($name))
{     echo “<p>Welcome <b>$name</b>!</p>”;
}
else
{
echo “<p>Enter a name</p>”;
}

if(!empty($_POST[‘products’]))
{
echo “<ul>”;
echo “<p>Your product choices are:<br/>”;
foreach ($_POST[‘products’] as $value)
{
echo “<li>$value</li>”;
}
echo “</ul>”;
}
else
{
echo “<p> Nothing selected</p>”;
}
?>

 

Advertisements

The Chinese Zodiac | a code demonstration for PHP

The Chinese Zodiac | a code demonstration for PHP

Chinese zodiac signs represent twelve different types of personalities. Traditionally beginning with the sign of the rat. Though the animal assigned for the birth year is not wholly who a person is, as there is also an animal assigned by the birth month called inner animals and by the birth hour called secret animals. These with a combination of five elements, make up 8,640 possible combinations for a persons personality trait, and all are considered important for the proper use of chinese astrology.

There are many versions of the story about the beginning of the zodiac, one such story begins with the rat being given the task on inciting the animals to report to the Jade Emperor to be selected for the zodiac. The cat being one of the animals selected was a good friend of the rat who tricked him into believing the banquet was a day later and the cat slept through it thinking it was not till the next day. When the cat found out he vowed to be the rats’ swore enemy for the ages.

use file store infomation to string

$outputstring = $date.”\t”.$tireqty.”\t”.$oilqty.” oil\t”.$sparkty.” spark plugs\t\$”.$totalamount.”\t”.$address.”\n”;

@$fp = fopen(“DOCUMENT_ROOT/../orders/orders.txt”,’ab’);

flock($fp,LOCK_EX);
if(!$fp){
echo “<p><strong>Your order could not be process at this time. Please try again later.</strong></p></body></html>”;
exit;
}
fwrite($fp, $outputstring,strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);

echo “<p>Order written.</p>”;

Loading Arrays from Files (use for loop)

<?php
$DOCUMENT_ROOT = $_SERVER[‘DOCUMENT_ROOT’];
$orders=file(“DOCUMENT_ROOT/../orders/orders.txt”);
$number_of_orders = count($orders);
if ($number_of_orders == 0){
echo ”

No orders pending.Please try again later.

“;

}else{

for ($i=0;$i<$number_of_orders;$i++){

echo $orders[$i].”
“;
}

}
?>

3 dimensional arrays with for loop

<?php
    $categories = array(array( array( ‘CAR_TIR’, ‘Tires’, 100 ),
                        array( ‘CAR_OIL’, ‘Oil’, 10 ),
                        array( ‘CAR_SPK’, ‘Spark Plugs’, 4 ) ),
                 array( array( ‘VAN_TIR’, ‘Tires’, 120 ),
                        array( ‘VAN_OIL’, ‘Oil’, 12 ),
                        array( ‘VAN_SPK’, ‘Spark Plugs’, 5 ) ),
                array( array( ‘TRK_TIR’, ‘Tires’, 150 ),
                        array( ‘TRK_OIL’, ‘Oil’, 15 ),
                        array( ‘TRK_SPK’, ‘Spark Plugs’, 6 ) )
                        );
    for ($layer =0;$layer <3; $layer++){
        echo “layer $layer<br/>”;
        for ($row =0; $row<3; $row++){
            for ($column =0; $column<3; $column++){
            echo ‘|’.$categories[$layer][$row][$column];
        
        }
            echo ‘|<br/>’;
        }
    
    }
    
    
    
    
?>

a simple sample for loop and while loop in php

$prices = array(‘Tires’=>100, ‘Oil’=>10, ‘Spark Plugs’=>4);

The foreach loop has a slightly different structure when using associative arrays.You
can use it exactly as you did in the previous example, or you can incorporate the keys as
well:
foreach ($prices as $key => $value) {
echo $key.” – “.$value.”<br />”;
}

The following code lists the contents of the $prices array using the each() construct:
while ($element = each($prices)) {
echo $element[‘key’];
echo ” – “;
echo $element[‘value’];
echo “<br />”;
}

There is a more elegant and more common way of doing the same thing.The construct
list() can be used to split an array into a number of values.You can separate two
of the values that the each() function gives you like this:
while (list($product, $price) = each($prices)) {
echo “$product – $price<br />”;
}

The output of this script fragment is shown in Figure 3.2.

Tires – 100
Oil – 10
Spark Plugs – 4

Visual Studio 2010 freedown + Crack

first:Microsoft Visual Studio 2010 down(come from www.microsoftstore.com

      (Premium) 【link】
       http://download.microsoft.com/download/F/F/8/FF8C8AF1-D520-4027-A844-8EC7BC0FB27C/X16-42546VS2010PremTrial1.iso

      (Professional)
       http://download.microsoft.com/download/4/0/E/40EFE5F6-C7A5-48F7-8402-F3497FABF888/X16-42555VS2010ProTrial1.iso

      (Ultimate)
       http://download.microsoft.com/download/2/4/7/24733615-AA11-42E9-8883-E28CDCA88ED5/X16-42552VS2010UltimTrial1.iso

then,Help->Register Product->:YCFHQ-9DWCY-DKV88-T2TMH-G7BHP then enter

Image

Image

or you can

       use thisProduct Key:YCFHQ9DWCYDKV88T2TMHG7BHP,to cover setup.sdb [Product Key]

if you already install fee trial, just change Product Key:YCFHQ9DWCYDKV88T2TMHG7BHP,then fine.

xml and xsl and css connected example

first, you need have a wine.xml,this is for store your wines database: see below:

<?xml version=”1.0″ encoding=”UTF-8″?>
<?xml-stylesheet type=”text/css” href=”wine.css”?>
<!DOCTYPE wines [
<!ELEMENT wines (wine+)>
<!ELEMENT wine (name,country,location,history,color,year,served)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT country (#PCDATA)>
<!ELEMENT location (#PCDATA)>
<!ELEMENT history (#PCDATA)>
<!ELEMENT color (#PCDATA|span)*>
<!ELEMENT span (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT served (#PCDATA)>
]>
<?xml-stylesheet type=”text/xsl” href=”wine.xsl”?>
<wines>
<wine>
<name>Rough Red</name>
<country>Italy</country>
<location>Turin</location>
<history>Some oenologists believe that Rough Red goes back to Roman times.</history>
<color>dark ruby-red wine – traditionally, it is called,<span>”black as rabbit’s blood”</span></color>
<year>2010</year>
<served>Rough Red should be served at 15 – 16 _C(59 – 60.8_F)
</served>
</wine>

<wine>
<name>Cabernet Merlot</name>
<country>South Australia</country>
<location>Australia</location>
<history>A soft, round and gloriously fleshy palate delivers flavours of ripe plum, red berries along with subtle liquorice and chocolate, finishing in a smooth and elegant fashion.
This is such an easy-drinking, soft and approachable wine. There is wonderful flavour and richness but it’s not at all confronting…a bit like a red wine with training wheels…and a true little treasure!</history>
<color>dark ruby-red wine – traditionally, it is called,<span>”black as rabbit’s blood”</span></color>
<year>2009</year>
<served>Rough Red should be served at 15 – 16 _C(59 – 60.8_F)
</served>
</wine>

</wines>

Then,save as win.xml you use xsl to style your wines’ data, see below(xml can let your xml data display in html ) Continue reading xml and xsl and css connected example

What is XML? What is XSL? What is the relationship between XML AND XSL?

What is XML?

  • XML stands for EXtensible Markup Language
  • XML is a markup language much like HTML
  • XML was designed to carry data, not to display data
  • XML tags are not predefined. You must define your own tags
  • XML is designed to be self-descriptive
  • XML is a W3C Recommendation

What is XSL?

XSLT is the recommended style sheet language of XML.

XSLT (eXtensible Stylesheet Language Transformations) is far more sophisticated than CSS.

XSLT can be used to transform XML into HTML, before it is displayed by a browser.

What is the relationship between XML AND XSL?

XSL gives your XML some style