|
-
Jun 17th, 2002, 01:04 AM
#1
Thread Starter
PowerPoster
Probably really easy - display images
I plan to use a frames page to post my photography online.
In the left frame will be thumnails. Clicking a thumbnail will display the image in the main frame.
All my photos have a unique ID already - that's how I name them. So my database table looks like this.
ImageID
Filename
Year
Subject
Sample data
ImageID = 18482
Filename =18482.jpg
Year = 1995
Subject = Scenic
In the PHP page I plan to have two variables that get pre-pended to the filename
$ThumbPath ='\images\thumbs\'
$ImagePath = '\images\'
What is the code for
1) Populating the images in the left frame based on subject. I know how to write the SQL statement, but how do I make it actually display the thumbs?
The thumb not only needs to be displayed, but it also needs to be a hyperlink.
2) When the viewer clicks the thumb, what is the code for displaying the image?
-
Jun 17th, 2002, 05:37 AM
#2
Fanatic Member
This should give you some ideas:
PHP Code:
//Connect to the Database before adding these lines
$query = mysql_query("select distinct Subject from tableName");
for ($i = 0; $i < mysql_numrows($query); $i++) {
$images = mysql_query("select * from tableName where Subject='".mysql_result($query,$i,"Subject")."'");
$ImageId = mysql_result($images,$i,"ImageId");
$Filename = mysql_result($images,$i,"Filename");
echo "<a href=\"realImage.php?id=$ImageId\" target="rightFrame"><img src=\"$ThumbPath$Filename\"></a><br>";
}
Then in your realImage.php page use $_GET['id'] to see what image they want to view and pull the Filename out of the database for viewing.
-
Jun 17th, 2002, 05:44 AM
#3
Thread Starter
PowerPoster
Thanks. As I was sitting here thinking about it, I realized that probably all I need to do is put an image on a page and give it a hyperlink and then look at the html.
I'm busy making up a set of thumbnails now and putting some data in the table so I can play around with this. If I have any more problems, I'll let you know.
Thanks.
-
Jun 17th, 2002, 07:00 AM
#4
Thread Starter
PowerPoster
cpradio, that's not quite what I'm looking for. I managed to convert your code, but I'm stuck again.
Basically, I want to have all the subjects (distinct row) in the left frame page.
Then when the user clicks the left frame page, I want the thumbnails to be displayed in the left frame instead of the subjects along with a link to "Subjects" that will display the subjects again.
I guess this means when the left page loads I have to check the variable $Subject to see if it contains anything. If it does, then display the thumbnails for that subject, otherwise display the subjects.
When the user clicks the thumbnail, I want to display the full-size image in the right frame (main.php).
can you help me with this?
-
Jun 17th, 2002, 07:01 AM
#5
Thread Starter
PowerPoster
Just to make sure I could get it working, I did this: This isn't what I want though because it displays the subject and then all the thumbnails. I plan to upload a couple hundred photographs, so that would be really slow page.
PHP Code:
<?php
$db = @mysql_connect(etc., etc.)
mysql_select_db('Photography');
$query = mysql_query("select distinct Subject from Photographs");
for ($i = 0; $i < mysql_numrows($query); $i++) {
echo mysql_result($query,$i,"Subject");
$images = mysql_query("select * from Photographs where Subject='".mysql_result($query,$i,"Subject")."'");
for ($j = 0; $j < mysql_numrows($images); $j++) {
$ImageId = mysql_result($images,$j,"ImageId");
$Filename = mysql_result($images,$j,"Filename");
$ThumbPath ='images/thumbs/';
echo "<p align=\"center\"> <img border=\"1\" <img src=\"$ThumbPath$Filename\"></a><br><br>";
}
}
?>
-
Jun 17th, 2002, 08:07 AM
#6
Fanatic Member
PHP Code:
//Connect to the Database before adding these lines
$query = mysql_query("select distinct Subject from tableName");
for ($i = 0; $i < mysql_numrows($query); $i++) {
if (isset($_GET['subject'])) {
$images = mysql_query("select * from tableName where Subject='".$_GET['subject']."'");
$ImageId = mysql_result($images,$i,"ImageId");
$Filename = mysql_result($images,$i,"Filename");
if ($i == 0)
echo "<a href=\"?\">Back To List</a><br>";
echo "<a href=\"realImage.php?id=$ImageId\" target="rightFrame"><img src=\"$ThumbPath$Filename\"></a><br>";
} else {
$allSubjects = mysql_result($query,$i,"Subject");
echo "<a href=\"?subject=$allSubjects\">$allSubjects</a><br>";
}
}
-
Jun 17th, 2002, 08:40 AM
#7
Thread Starter
PowerPoster
cpradio, I'm not clear on what you're doing. It looks to me like the code you wrote will give either one thumbnail per subject or the subject text.
What I'm looking for is something that gives all the subjects or all the thumbnails from the selected subject.
Your code only loops through the number of subjects but never addresses the number of thumbnails in the subject.
I think I'm close, but I don't know how to write this line:
PHP Code:
// this is the line I'm having trouble with
echo "<p><a href=\"$Temp\">\"$Temp\"</a></p>"
Here it is in context:
PHP Code:
If ($Subject == "")
{
echo "Subjects<br><br>";
$query = mysql_query("SELECT DISTINCT Subject FROM Photographs");
for ($i = 0; $i < mysql_numrows($query); $i++) {
$temp = mysql_result($query,$i,"Subject")
echo "<p><a href=\"$Temp\">\"$Temp\"</a></p>"
}
}
else
{
$images = mysql_query("SELECT * FROM Photographs WHERE Subject= $Subject");
for ($i = 0; $i < mysql_numrows($images); $i++) {
$ImageId = mysql_result($images,$i,"ImageId");
$Filename = mysql_result($images,$i,"Filename");
$ThumbPath ='images/thumbs/';
echo "<a href=\"main.php?id=$ImageId\" target=\"rightFrame\"><img src=\"$ThumbPath$Filename\"></a><br>";
// echo "<p align=\"center\"> <img border=\"1\" <img src=\"$ThumbPath$Filename\"></a><br><br>";
}
}
-
Jun 17th, 2002, 02:30 PM
#8
Fanatic Member
Oops, sorry about that. I have been writing this on and off at work and lately its gotten to the point to where I have not had time to thoroughly look at what I wrote.
The problem with yours is first you do not need \" around the second $Temp as I only use that so the <a href=" "> quotes appear.
Secondly PHP is case sensative, you have defined the subject name in $temp and not $Temp.
PHP Code:
//Connect to the Database before adding these lines
if (isset($_GET['subject'])) {
$query = mysql_query("select distinct Subject from tableName");
for ($i = 0; $i < mysql_numrows($query); $i++) {
$images = mysql_query("select * from tableName where Subject='".$_GET['subject']."'");
$ImageId = mysql_result($images,$i,"ImageId");
$Filename = mysql_result($images,$i,"Filename");
if ($i == 0)
echo "<a href=\"?\">Back To List</a><br>";
echo "<a href=\"realImage.php?id=$ImageId\" target="rightFrame"><img src=\"$ThumbPath$Filename\"></a><br>";
}
} else {
for ($i = 0; $i < mysql_numrows($query); $i++) {
$allSubjects = mysql_result($query,$i,"Subject");
echo "<a href=\"?subject=$allSubjects\">$allSubjects</a><br>";
}
}
Last edited by cpradio; Jun 17th, 2002 at 02:34 PM.
-
Jun 17th, 2002, 10:41 PM
#9
Thread Starter
PowerPoster
Actually, I figured it out a while ago, but I couldn't post it because VB Forums was down or something. But I actually got it working.
The frames page is index.htm
the left frame is index.php
the right frame is main.php
PHP Code:
// index.php
$imgURL ="index.php?NewSubject="; // Set subject to Null
echo "<A HREF=$imgURL Target =\"contents\">Subjects</a></br></br>";
If ($NewSubject == '') // User selected to view Subjects
{
$query = mysql_query("SELECT DISTINCT Subject FROM Photographs ORDER BY Subject");
for ($i = 0; $i < mysql_numrows($query); $i++) {
$NewSubject = mysql_result($query,$i,"Subject");
$imgURL ="index.php?NewSubject=$NewSubject";
echo "<A HREF=$imgURL Target=\"contents\">$NewSubject</a></br>";
}
}
else // Display thumbnails associated with selected subject
{
$query = mysql_query("SELECT ImageID, Filename FROM Photographs WHERE Subject = '$NewSubject'");
//echo "$NewSubject</br></br>";
for ($i = 0; $i < mysql_numrows($query); $i++) {
$Filename = mysql_result($query,$i,"Filename");
$ThumbPath ='images/thumbs/';
$ImageID = mysql_result($query,$i,"ImageID");
echo "<p align=\"center\"><a href=\"main.php?ImageID=$ImageID Target=\"main\"> <img src=\"$ThumbPath$Filename\"></a></p>";
}
}
PHP Code:
// main.php
if ($ImageID > 0)
{
$db = @mysql_connect(blah, blah);
mysql_select_db('Photography');
$query = mysql_query("SELECT Subject, Filename, Year FROM Photographs WHERE ImageID = '$ImageID'");
$BasePath = 'images/';
$Filename = mysql_result($query,0,"Filename");
$FullPath = "$BasePath$Filename";
echo "<p align=\"center\"><img src=$FullPath></p>";
echo "$Caption</br>";
$Copyright = "Copyright ";
$Year =mysql_result($query,0,"Year");
$Author = "Paul K. Johnson";
echo "$Copyright$Year$Author";
}
-
Jun 18th, 2002, 04:56 AM
#10
Thread Starter
PowerPoster
-
Jun 18th, 2002, 05:06 AM
#11
Fanatic Member
-
Jun 18th, 2002, 05:10 AM
#12
Thread Starter
PowerPoster
Originally posted by cpradio
COOL, looks really good.
Thanks. And thanks for your help. Now I need a new project. But not a forum.
-
Jun 18th, 2002, 05:32 AM
#13
Fanatic Member
Well, first, I would say you should make your script 4.2 compatabile by using
$imageId = $_GET['ImageId']; right above your if statement in your main.php file
and $newSubject = $_GET['NewSubject']; right above your if statement in your list.php
If you are looking for a new project I would attempt a Guestbook with ip logging, and allowing an admin to go in and delete any entries he/she desires. 
-Matt
-
Jun 18th, 2002, 05:43 AM
#14
Thread Starter
PowerPoster
-
Jun 18th, 2002, 06:54 AM
#15
Fanatic Member
Okay, content management system.
-
Jun 18th, 2002, 06:56 AM
#16
Thread Starter
PowerPoster
Originally posted by cpradio
Okay, content management system.
????
-
Jun 18th, 2002, 07:07 AM
#17
Fanatic Member
A script were anyone could easily update pages of their site via an online form.
Add, Remove, Modify text, news, whatever from a Control Panel.
-Matt
-
Feb 9th, 2003, 07:49 PM
#18
Junior Member
guys! guys!
i really think you really really really should take a look at Lotus Notes....
have you ever heard of that? ever bothered to check it? i work with Lotus Notes (notes.net), and i came to check this board, and felt really sorry for the way the PHP guys work out there.. here's my advice that may chnage your life forever.. just try it.. it'll be hard at first, just like anything new. it's a powerful database environmet. you put your code and run it in the database, and the server (Lotus Domino) works for you by converting your documents into html pages for online viewing, then u can edit, delete, create and do all that you ever dream to do with PHP, but the difference is that it doesnt need coding, you just make the form, then fill out the documents or edit them online or whatever..
just take a look, u wont regret it.. check lotus.com and notes.net..
unfortunately, Lotus and IBM do not make enough advertisement for this, but i think u can do your way through their site. search for "Notes"
Best wishes!
-
Feb 9th, 2003, 09:20 PM
#19
Stuck in the 80s
Originally posted by ai.unit
...
You know what the funny thing is? We're programmers, developers, coders...we want to code.
Ever thought of that?
-
Feb 10th, 2003, 04:07 AM
#20
Originally posted by The Hobo
You know what the funny thing is? We're programmers, developers, coders...we want to code.
Ever thought of that?
ROFL 
True, true. If we were that lazy, we might as well download PHP Nuke, and stay restricted to that 'method.' Perhaps you should try coding yourself...
-
Feb 10th, 2003, 04:08 AM
#21
BTW...
That wasn't directed at you, Hobo.
-
Feb 10th, 2003, 04:36 AM
#22
Conquistador
even though i have no experience with lotus notes, i can confidently say that there are things you could do in php that prolly couldn't be done in lotus.
it's like saying "don't make programs in vb because someone else already has" (well maybe )
:/
-
Feb 10th, 2003, 09:33 AM
#23
Junior Member
thank yo guys for the replies but hey, did i say u dont need to code in Notes? of course we are all developers and coders, but i meant to say that Notes is of a higher level and u never need to bother with the little things again like how to compose the presice HTML of a document etc, because this is a basic functionality in Notes while you can concentrate on your other work, making additional enhancements, and i'm meaning by this the project of Content Management that cpradio suggested earlier which can be done with almost no coding at all, but additional coding would be required (for example) for field validation... (as for me, i do have A LOT of coding in any app i make in Notes, and i work in a company, and we do make projects that take a whole year of development in Notes).
another thing that got my attention is the way you need to do an sql query to look up data and make a loop... for ready-made queries (i dont know what you call them exactly) there what is called a "view" in notes, and the good thing u'll love about is that it has the ability to process the code you write for each document without the need to get into a loop or something.. of course i'm not making an advertisement here, but i just remember the days i used to work in VB and do all the coding there.. now i'm on a higher level, and i feel the same for PHP..
of course VB and PHP can do things Notes cant do, no 2 programming langs are the same, but hey, why am i saying all this here?
well, the actual reason why i came here was because i'm making a photoalbum with Notes, and so far i thought of generating the thumbnails dynamically (the guys at php.net said it wont be that much a heavy load to the server, so it's ok to do it), and i'm willing to have like 10 thumbs per page so it'll be ok.. after looking around, i got the following PHP code wich generates the thumbnail image:
PHP Code:
function loadjpeg($path, $max_x, $max_y) {
$im = @imagecreatefromjpeg($path);
if (!$im) {
$im = imagecreate(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, "Error loading $path", $tc);
}
if ($max_x != 0 && $max_y != 0) {
$x = imagesx($im);
$y = imagesy($im);
if ($x > $max_x) {
$y = (int)floor($y * ($max_x / $x));
$x = $max_x;
}
if ($y > $max_y) {
$x = (int)floor($x * ($max_y / $y));
$y = $max_y;
}
if (imagesx($im) != $x || imagesy($im) != $y) {
$tmp = imagecreate($x, $y);
imagecopyresized($tmp, $im, 0, 0, 0, 0, $x, $y, imagesx($im), imagesy($im));
imagedestroy($im);
$im = $tmp;
}
}
return $im;
}
as i could understand the code takes the url of the image along with a maximum dimension parameter and returns the tiny image, but my problem is that i'm still a total nerd in php, and luckily enough, my web host offer PHP functionality in the hosting package alongside with Lotus Domino, anyway,i just thought of showing you what i'm willing to do so u may help me with this as it's being hard for me to deal with PHP...
my problem in the previous function was how to pass the parameters, but reading through this thread i found out that i can do something like www.thing.com/page.php?imgurl=so&so&size=xyz
so here's what i'm willing to do to get a single thumbnail:
in html:
<img src="phpPath/getthumb.php?url=imgurl">
and in the php file (getthumb.php) i'd have the function mentioned above and the following:
PHP Code:
if (isset($_GET['url'])) {
$max_x = 150
$max_y = 150
return loadjpeg($_GET['url'], $max_x, $max_y)
}
[I]function loadjpeg goes here[/I]
so tell me, it'll work like this, no? i will give it a try this evening..
-
Feb 10th, 2003, 10:05 AM
#24
Junior Member
well it didnt work...
you can try it here:
http://yusran.com/php/php.exe/getthu...sf/head-en.gif!OpenImageResource
any ideas?
here's my complete php code
PHP Code:
<?php
if (isset($_GET['url'])) {
$max_x = 150;
$max_y = 150;
return loadjpeg($_GET['url'], $max_x, $max_y);
}
function loadjpeg($path, $max_x, $max_y) {
$im = @imagecreatefromjpeg($path);
if (!$im) {
$im = imagecreate(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, "Error loading $path", $tc);
}
if ($max_x != 0 && $max_y != 0) {
$x = imagesx($im);
$y = imagesy($im);
if ($x > $max_x) {
$y = (int)floor($y * ($max_x / $x));
$x = $max_x;
}
if ($y > $max_y) {
$x = (int)floor($x * ($max_y / $y));
$y = $max_y;
}
if (imagesx($im) != $x || imagesy($im) != $y) {
$tmp = imagecreate($x, $y);
imagecopyresized($tmp, $im, 0, 0, 0, 0, $x, $y, imagesx($im), imagesy($im));
imagedestroy($im);
$im = $tmp;
}
}
return $im;
}
?>
-
Feb 11th, 2003, 06:27 AM
#25
Originally posted by ai.unit
well it didnt work...
Ohh... the irony of it all
-
Feb 11th, 2003, 09:35 AM
#26
Junior Member
-
Feb 12th, 2003, 10:34 AM
#27
It's best you start a new thread, explaining your problem. That should elicit more responses.
By the way, where in Damascus do you live? I used to live there myself
-
Feb 12th, 2003, 10:47 AM
#28
Frenzied Member
Originally posted by ai.unit
guys! guys!
i really think you really really really should take a look at Lotus Notes....
have you ever heard of that? ever bothered to check it? i work with Lotus Notes (notes.net), and i came to check this board, and felt really sorry for the way the PHP guys work out there.. here's my advice that may chnage your life forever.. just try it.. it'll be hard at first, just like anything new. it's a powerful database environmet. you put your code and run it in the database, and the server (Lotus Domino) works for you by converting your documents into html pages for online viewing, then u can edit, delete, create and do all that you ever dream to do with PHP, but the difference is that it doesnt need coding, you just make the form, then fill out the documents or edit them online or whatever..
just take a look, u wont regret it.. check lotus.com and notes.net..
unfortunately, Lotus and IBM do not make enough advertisement for this, but i think u can do your way through their site. search for "Notes"
Best wishes!
lotus notes??? not even in the same ball park. for one it is expensive (what else did you expect from IBM) and only runs in windows (and mac) environment. at least that is what I read. php can run anywhere. php is FREE, lotus notes is not.
you can't come here to tell us that you feel sorry for us becasue notes is soooo much better than php. well if you like it so much then don't do php. also you can only work with what the environment will let you work with, if you have to run notes than fine, run it, but we can't or don't want to so we don't.
-
Feb 12th, 2003, 05:58 PM
#29
Junior Member
-
Feb 12th, 2003, 07:45 PM
#30
Frenzied Member
and where on php.net will you be making this thread????
-
Feb 12th, 2003, 08:44 PM
#31
Junior Member
Originally posted by phpman
and where on php.net will you be making this thread????
good Q! i thought there's a public forum.. but i reemmbered that one can post a msg in the functions secion of the site.. i think i'll post it under the 'imagecreate' function...
or maybe here on this forum... or even both.. LOL.. i was in a hurry to find the answer why my code wasn't working, but now i am assigned some work, and i aint free as much as i was a few days ago...
-
Feb 12th, 2003, 10:07 PM
#32
Rabat Building, just near Damascus Community School. Great place, I really liked it. I especially like Sookh Hamidiye for some reason.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|