Hi !!!
Today, I’ll start coding that memo system I was talking about a few days ago.
But, suddenly, I came up with an idea for my image gallery :
I’m sure it has been done already, but I was wondering :
would it be possible to store all images in a SQL db, and also the text that goes with them, so that I wouldn’t have to make a page for each image, but rather just send parameters when the user clicks on the thumbnails ?
Then, when the user views an image, is it possible to have a “next ” and “previous” button that would load the next or previous image in the db ?
I think I’m going to need a few advice on this one, cause I don’t know at all how to start…
It would be something like that : [url]http://enfantsdelo.free.fr/eli.htm
but done in php.
( don’t really pay attention to the ugliness of the page, it’s old, and the css is missing )
Thanks for the help !!!!
[code=php]
$query = "SELECT title
,description
,file
FROM images
WHERE img_nbr
=3";
$result = mysql_query($query) or die("SQL error: " . mysql_error());
if($row = mysql_fetch_assoc($result))
{
echo "<h3>{$row['title']}</h3>n";
echo "<p><img src='img/{$row['file']}' alt='{$row['title']}'></p>n";
echo "<p>{$row['description']}</p>n";
}
[/code]
[code=php]
while ($i < $imageClass->Fields('total_rows')) {
echo '<img src="' . $imageClass->Fields('img_thumb_src') . '" width="' . $imageClass->Fields('img_width') . '" height="' . $imageClass->Fields('img_height') . '" alt="' . $imageClass->Fields('img_alt') . '"><a href="' . $_SERVER['PHP_SELF'] . '?img_id=' . $imageClass->Fields('img_id') . '" class="someclass">' . $imageClass->Fields('img_text') . "</a>rn";
}
[/code]
[code=php]
<?php
// SQL database Variables
$hostname="sql.free.fr";
$user="myusername";
$pass="mypasswd";
$dbase="enfantsdelo";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
$imgname=mysql_result(mysql_query('select file from image where '$id'='$_GET['id']',$connection'),0);
$imgtitle=mysql_result(mysql_query('select title from image where '$id'='$_GET['id']',$connection'),0);
$imgdesc=mysql_result(mysql_query('select desc from image where '$id'='$_GET['id']',$connection'),0);
echo $imgtitle;
?>
<img src=<?php $imgname; ?>>
<?php echo $imgdesc; ?>
[/code]
[code=php]
$imgname = mysql_result(mysql_query('SELECT file FROM image WHERE '.$_GET['id'].'='id'',$connection));
[/code]
[code=php]
$imgname = mysql_result(mysql_query('SELECT file FROM image WHERE '.$_GET['id'].'='id'',$connection));
$imgtitle = mysql_result(mysql_query('SELECT title FROM image WHERE '.$_GET['id'].'='id'',$connection));
$imgdesc = mysql_result(mysql_query('SELECT desc FROM image WHERE '.$_GET['id'].'='id'',$connection));
[/code]
[code=php]
<?php
// SQL database Variables
$hostname="sql.free.fr";
$user="username";
$pass="passwd";
$dbase="enfantsdelo";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
$imgname = mysql_result(mysql_query('SELECT file FROM image WHERE '$_GET['id']'='id'',$connection),0);
$imgtitle = mysql_result(mysql_query('SELECT title FROM image WHERE '$_GET['id']'='id'',$connection),0);
$imgdesc = mysql_result(mysql_query('SELECT desc FROM image WHERE '$_GET['id']'='id'',$connection),0);
echo $imgtitle;
?>
<html>
<title>no title</title>
<head></head>
<body>
<img src=<?php $imgname; ?>>
<?php echo $imgdesc; ?>
</body>
</html>
[/code]
sorry, I've got to go, but I'll be back soon... This image gallery won't see me defeated !!!! è__é[/QUOTE]
[code=php]
<?
// connection stuff here
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
$getid=$_GET['id'];
$imgname = mysql_result(mysql_query('SELECT file FROM image WHERE ID='$getid'',$connection),0);
$imgtitle = mysql_result(mysql_query('SELECT title FROM image WHERE ID='$getid'',$connection),0);
$imgdesc = mysql_result(mysql_query('SELECT desc FROM image WHERE ID='$getid'',$connection),0);
?>
<html>
<title>no title</title>
<head></head>
<body>
<p><?php $imgtitle; ?></p>
<img src='<?php echo $imgname; ?>'>
<?php echo $imgdesc; ?>
</body>
</html>
[/code]
[code=php]
$getid = $_GET['id'];
$imgname = mysql_result(mysql_query("SELECT file FROM image WHERE ID='$getid'",$connection),0);
$imgtitle = mysql_result(mysql_query("SELECT title FROM image WHERE ID='$getid'",$connection),0);
$imgdesc = mysql_result(mysql_query("SELECT desc FROM image WHERE ID='$getid'",$connection),0);
?>
<html>
<title>no title</title>
<head></head>
<body>
<p><?php $imgtitle; ?></p>
<img src='<?php echo $imgname; ?>'>
<?php echo $imgdesc; ?>
<a href="http://enfantsdelo.free.fr/image.php?id='$getid'+1">Next</a>
</body>
</html>
[/code]
[code=php]
<?php
// SQL database Variables
$hostname="";
$user="";
$pass="";
$dbase="";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
$getid = $_GET['id'];
$imgname = mysql_result(mysql_query("SELECT file FROM image WHERE ID='$getid'",$connection),0);
$imgtitle = mysql_result(mysql_query("SELECT title FROM image WHERE ID='$getid'",$connection),0);
$imgdesc = mysql_result(mysql_query("SELECT des FROM image WHERE ID='$getid'",$connection),0);
?>
<html>
<title>no title</title>
<head></head>
<body>
<?
echo "<p>" .$imgtitle. "</p>";
echo "<img src=" .$imgname. ">";
echo "<p>" .$imgdesc. "</p>";
echo "<a href=http://enfantsdelo.free.fr/image.php?id=".($getid+1).">Next</a>";
?>
</body>
</html>
[/code]
will this work, '$getid+=1', instead of '$getid'+1[/QUOTE]
[code=php]
<?php
// SQL database Variables
$hostname="";
$user="";
$pass="";
$dbase="";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
$getid = $_GET['id'];
$imgname = mysql_result(mysql_query("SELECT file FROM image WHERE ID='$getid'",$connection),0);
$imgtitle = mysql_result(mysql_query("SELECT title FROM image WHERE ID='$getid'",$connection),0);
$imgdesc = mysql_result(mysql_query("SELECT des FROM image WHERE ID='$getid'",$connection),0);
$retour = mysql_query('SELECT COUNT(*) AS imgnb FROM image');
$donnees = mysql_fetch_array($retour);
$nbre = $donnees['imgnb'];
?>
<html>
<?
echo "<title>" .$imgtitle. "</title>"; ?>
<head></head>
<body>
<?
echo "<p>" .$imgtitle. "</p>";
echo "<img src=" .$imgname. ">";
echo "<p>" .$imgdesc. "</p>";
echo "<p><a href=http://enfantsdelo.free.fr/image.php?id=".($getid-1).">Previous</a>";
echo " | ";
echo "<a href=http://enfantsdelo.free.fr/image.php?id=".($getid+1).">Next</a></p>";
echo "<p>There are ".$nbre." images in the db</p>";
?>
</body>
</html>
[/code]
0.1.9 — BETA 5.20