sorry i missunderstood what you wanted ill give you both: here is the thumbnails page:
PHP Code:
<?php
/* set up the database connection because real_escape_string() relies on an open connection to work */
$dbLink = new mysqli('localhost', 'root', '', 'gallery');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
/* check that $_GET['gallery'] has a value and the value is numeric - ie someone hasn't changed the url to just gallery.php or tried to be clever & entered gallery.php?gallery=bob */
if(isset($_GET['gallery']) && is_numeric($_GET['gallery'])) {
/* $_GET['gallery'] passes our test, so perform security functions on it & assign it to the $gallery variable */
$gallery = $dbLink->real_escape_string($_GET['gallery']);
} else {
/* it doesn't exist or it isn't numeric so assign a default value so our query below always gets constructed properly & safely */
$gallery = 1;
}
/* construct the query */
$query = "SELECT id, name, size, image_path FROM images WHERE gallery_type_id = $gallery";
/* run the query */
$result = $dbLink->query($query);
/* loop through the results & display the images */
while ($row = $result->fetch_assoc()) {
echo "<a href=\"image.php?id=" . $row['id'] . "\">";
echo "<img src=\"imageResize.php?imageFilename=" . $row['name'] . "&maxHeight=120,&maxWidth=150\" />\n";
echo "</a>\n";
}
?>
and here is image.php
PHP Code:
<?php
$dbLink = new mysqli('localhost', 'root', '', 'gallery');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
if(isset($_GET['id']) && is_numeric($_GET['id'])) {
/* $_GET['id'] passes our test, so perform security functions on it & assign it to the $id variable */
$id= $dbLink->real_escape_string($_GET['id']);
} else {
/* it doesn't exist or it isn't numeric so assign a default value so our query below always gets constructed properly & safely */
$id = 1;
}
/* construct the query */
$query = "SELECT name, size, image_path FROM images WHERE id = $id";
/* run the query */
$result = $dbLink->query($query);
while($row = $result->fetch_row()) {
echo "<img src=\"" . $row[2] . "\" />"; // you could also play with the other $row[] variables returned by the query here.
}
?>
Bookmarks