Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Drawing the Layout - Page 12

January 12, 2001

As we said earlier, we ultimately want our results displayed in a diagram, so let's modify mall.php to display the information graphically.

<?php
//mall2.php
include "./common_db.inc";
if ($criteria!="") {
	$link_id = db_connect('mapping');
	$query = "SELECT m_id FROM mall
		WHERE m_desc LIKE '%".$criteria."%'";
	$mallResult = mysql_query($query,$link_id);
	if (mysql_num_rows($mallResult) > 0) {
		$stores = array();
		while ($mallRow = mysql_fetch_array($mallResult)) {
		$stores[count($stores)] = $mallRow[0];
		}
		mysql_free_result($mallResult);
		$show = implode(",",$stores);
		echo "<IMG SRC=\"showmall.php?show=".urlencode
			$show)."\">";
	} else {
		echo "no shops found";
	}
}
?>
[Lines 6 and 7 above are one line as are lines 15 and 16. They have been split for formatting purposes.]

All the image creation tasks are farmed out to a new script, showmall.php:

<?php
//showmall.php
include "./common_db.inc"
Header("Content-type: image/png");
if ($show!="") {
	$image = ImageCreateFromPNG("groundfloor.png");
	$shops = explode(",", urldecode($show));
	$link_id = db_connect('mapping');
	$gray = ImageColorAllocate($image, 204, 204, 204);
	for ($x=0; $x<count($shops); $x++) {
		$query = "SELECT m_center FROM mall
			WHERE m_id=".$shops[$x];
		$mallResult = mysql_query($query, $link_id);
		$mallRow = mysql_fetch_array($mallResult);
		$center = explode(",", $mallRow[0]);
		ImageFill($image, $center[0], $center[1], $gray);
	}
} else {
	$image = ImageCreate(100,50);
	$white = ImageColorAllocate($image, 255, 255, 255);
	$black = ImageColorAllocate($image, 0, 0, 0);
	ImageString($image, 5, 1, 1, "Error", $black);
}
ImagePNG($image);
ImageDestroy($image);
?>
[Lines 11 and 12 above are one line. They have been split for formatting purposes.]

If we perform the same search again, the result should look more like the figure shown below.

image 21.jpg

Our two PHP scripts mall.php and showmall.php work together to create the finished result you see above. The former handles the criteria we've passed from our menu form in the sidebar. It builds an HTML IMG tag, whose SRC attribute will specify the showmall.php script; it's this that actually draws the image.

The first thing we do in mall.php is to test that the user has entered something in the text box:

<?php
//mall2.php
include "./common_db.inc";
if ($criteria!="") {
We then connect to database mapping and make a SQL query based on the user-entered value of $criteria. If any results are returned, we can process them:
$link_id  =  db_connect('mapping');
$query  =  "SELECT m_id FROM mall
WHERE m_desc LIKE '%".$criteria."%'";
$mallResult  =  mysql_query($query,$link_id);
if  (mysql_num_rows($mallResult) >  0){
[Lines 2 and 3 above are one line. They have been split for formatting purposes.]

We need to communicate these results to showmall.php, so we pass through a comma-separated list of the shops that need to be highlighted.

Building A Framework - Page 11
Beginning PHP4
Continuing the Layout - Page 13


Up to => Home / Authoring / Languages / PHP / BeginningPHP4




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers