[thelist] Using php/mysql to retrieve URL's
John Corry
webshot at members.evolt.org
Tue Jul 23 14:27:00 CDT 2002
> CREATE TABLE 'images' (
> 'id' INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
> 'filename' VARCHAR(50) NOT NULL,
> 'alt' VARCHAR(255) NOT NULL,
> 'width' INT NOT NULL,
> 'height' INT NOT NULL
> );
>
> Then you can generate your links like this:
>
> <?php
>
> // assume db connection is up and running
> // assume image id is held in a variable called $id
>
> $path = "/path/to/my/images/";
>
> $s = "SELECT filename, alt, width, height FROM images WHERE
> id = '". $id. "'"; $q = mysql_query ($s); $r = mysql_fetch_array ($q);
>
> ?>
>
> <img src="<?=$path . $r["filename"]?>
> alt="<?=$r["alt"]?>
> width="<?=$r["width"]?>
> height="<?=$r["height"]?> />
>
PHP has a very cool function, GetImageSize
(http://www.php.net/getimagesize/ .
This will save you from storing the width/height in the db...
John Corry
More information about the thelist
mailing list