Re: Array help

From: Date: Fri, 23 Jul 2004 21:13:41 +0000
Subject: Re: Array help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-191694@lists.php.net to get a copy of this message
> I've got a field in my database that contains a single numerical character > ("1" or "2" or "3", etc.). I need to load a different background > image in > one cell of a table depending upon what the number the field contains. > What's the easy syntax for associating entries in the field ("1" or > "2" or > "3", etc.) with image filenames ("bkgrnd-default.gif" or > "bkgrnd-positive.gif" or "bkgrnd-negative.gif", etc.) $images[1] = 'bkgrnd-default.gif'; $images[2] = 'bkgrnd-positive.gif'; $images[3] = 'bkgrnd-negative.gif'; do you query, get the result in a variable, I'll use $field <img src="<?php echo $images[$field];?>" /> you could do some error checking to make sure the value in $field exists in the $images array

« previous php.general (#191694) next »