spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php / beginning / chap16 / 2 To page 1current pageTo page 3
[previous] [next]

Beginning PHP4

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Adding data

Here's a SQL script to populate our mall table with its data.

INSERT INTO mall VALUES (1,'G','G1','Fast Snax',
            '555-7089','150,0,150,100,200,100,200,0','175,50',
            'food,sweets,soda,drinks,chips,cola,pies,fast food,candy');
INSERT INTO mall VALUES (2,'G','G2','ACME Newsagent',
            '555-6843','300,0,300,100,350,100,350,0','325,50',
            'newspapers,magazines,paper,stationary,newsagents,periodicals');
INSERT INTO mall VALUES (3,'G','G3','Fashion Warehouse',
            '555-7521','350,0,350,100,400,150,500,150,500,0','425,65',
            'clothes,clothing,shoes,pants,suits,dresses');
INSERT INTO mall VALUES (4,'G','G4','CD&#059; R Us',
            '555-0459','400,150,400,250,500,250,500,150','450,200',
            'cds,dvds,music,tapes,videos,rock,pop');
INSERT INTO mall VALUES (5,'G','G5','Garden Bounty Florists',
            '555-9561','400,250,400,350,500,350,500,250','450,300',
            'gardening,flowers,florists,arrangements,floral');
INSERT INTO mall VALUES (6,'G','G6','National Bank',
            '555-3675','400,350,350,400,350,500,500,500,500,350','425,440',
            'money,banks,banking,cheques,deposit,withdrawal,cash,atm');
INSERT INTO mall VALUES (7,'G','G7','Sweetime',
            '555-7659','300,400,300,500,350,500,350,400','325,450',
            'candy,sweets,candy floss,cola,sodas,drinks,chips,crisps');
INSERT INTO mall VALUES (8,'G','G8','The Classics',
            '555-4395','150,400,150,500,200,500,200,400','175,450',
            'cds,dvds,music,jazz,classics');
INSERT INTO mall VALUES (9,'G','G9','The Computer Matrix',
            '555-7001','100,350,150,400,150,500,0,500,0,350','65,435',
            'pc,computers,components,software,hardware,books,cds');
INSERT INTO mall VALUES (10,'G','G10','Bibliophile',
            '555-3752','100,250,100,350,0,350,0,250','50,300',
            'books,magazines,periodicals,reading');
INSERT INTO mall VALUES (11,'G','G11','Well Heeled',
            '555-2564','0,150,100,150,100,250,0,250','50,200',
            'shoes,trainers,boots,heels');
INSERT INTO mall VALUES (12,'G','G12','The Great Outdoors',
            '555-7269','0,0,0,150,100,150,150,100,150,0','65,70',
            'hiking,camping,rafting');

We can save it as map_data.sql and import it into our mapping database:


> mysql -u phpuser -pphppass mapping < map_data.sql

Testing our data

The coordinates for the outline of the shops are now all stored in our database. In order to test that everything is working correctly we are going to write a script to create an image of our mall.

Try It Out - Drawing The Mall
<?php
//drawmall.php
include "./common_db.inc";

Header("Content-type: image/png");


$image = ImageCreate(501,501);
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);

$link_id = db_connect('mapping');

$query = "SELECT m_area FROM mall";
$mallResult = mysql_query($query,$link_id);

while ($mallRow = mysql_fetch_array($mallResult)) {
   $area = explode(",", $mallRow[0]);
   for ($i=0; $i &lt; count($area)-2; $i=$i+2) {
      ImageLine($image,$area[$i],$area[$i+1],$area[$i+2],$area[$i+3],$black);
   }
   ImageLine($image,$area[count($area)-2],
                    $area[count($area)-1], $area[0], $area[1], $black);
}

for ($i=0; $i&lt;count($area)-2; $i=$i+2) {
   ImageLine($image,$area[$i], $area[$i+1], $area[$i+2], $area[$i+3], $black);
}
ImageLine($image, $area[count($area)-2],
                  $area[count($area)-1], $area[0], $area[1], $black);
   ImagePNG($image);
   ImageDestroy($image);
   mysql_free_result($mallResult);
?>

When you run this script, you should see the image below:

2

home / programming / php / beginning / chap16 / 2 To page 1current pageTo page 3
[previous] [next]

Copyright 1999 Wrox Press Ltd. and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution


Revised: March 19, 2001
Created: March 19, 2001


URL: http://webreference.com/programming/php/beginning/chap16/2/