Log in

View Full Version : picture viewer



jr_yeo
07-31-2006, 09:19 AM
<?
$query1 = "SELECT $uniquerow, prev_path, filename FROM $tablename";
$rs = mysql_query($query1);
$randomId = array();
while($row = mysql_fetch_array($rs))
array_push($randomId, $row['id']);
$randomId = $randomId[rand(0, count($randomId))]
?>
<script>
function populateSelect(selectobj){
for (var i=0; i<randomId.length; i++)
selectobj.options[selectobj.options.length]=new Option(randomId[i], randomID[i])
if (selectobj.options.length>1){
selectobj.selectedIndex=0
showpicture(document.getElementById("picsform").picslist)}}</script>
is the code possible? tnx.

djr33
07-31-2006, 09:40 AM
Er.... is WHAT possible?

jr_yeo
07-31-2006, 09:52 AM
the code that i just posted? :p

djr33
07-31-2006, 09:55 AM
Yes, you just posted code. Very possible. :p
But, what, exactly, would you like to do with the code?
If you've run it and there are problems, what are they? What would you like different? Etc.
Or, is, perhaps, this simply an easier/smaller version of what is on the site?
I didn't see the code there, so I'm not sure what specifically you are referring to.


Note that:
"Does this work?"
and
"How do you do this...?"
are very different questions, though both do require more information.

jr_yeo
07-31-2006, 10:09 AM
on this link (http://www.javascriptkit.com/script/script2/phpviewer/), the images are being read by using 'getpics.php'.
now i have a database for images. i want to get images from the database and the resultset pass thru the script, something like:


<?
$query1 = "SELECT $uniquerow, prev_path, filename FROM $tablename";
$rs = mysql_query($query1);
$randomId = array();
while($row = mysql_fetch_array($rs))
array_push($randomId, $row['id']);
$randomId = $randomId[rand(0, count($randomId))]
?>
<script>
function populateSelect(selectobj){
for (var i=0; i<randomId.length; i++)
selectobj.options[selectobj.options.length]=new Option(randomId[i], randomID[i])
if (selectobj.options.length>1){
selectobj.selectedIndex=0
showpicture(document.getElementById("picsform").picslist)}}</script>
the code betwen the <script></script> tags are just part of you will see in the link provided. how do i make this work?

djr33
07-31-2006, 10:14 AM
Ah, now we're getting somewhere.

You've run it? What doesn't work?

First... this is php, I think, right? Looks like it from the code, and the link... you don't have an open php tag; you need to start it <?php, not <?.
Maybe that's the whole issue?

Too tired right now to analyze the wholet thing.


You will also need to output the values to the javascript, not just keep them in PHP.
For exaple:
<script>
<?php echo "var = 'value';"; ?>
</script>

jr_yeo
07-31-2006, 10:20 AM
from what read somewhere in this forum, PHP and javascript dont mix very well. like oil and water :cool:

You've run it?,
not yet. coz logically speaking, its correct. but script wise, i know m missing something. i just dunno what.

Too tired right now to analyze the wholet thing.
sure np anytime ur batteries are recharged :D

BLiZZaRD
07-31-2006, 10:22 AM
I am not a JS or a php guy, I am still trying to learn them myself... but if you are trying to access and pull images from the database, don't you need the host/user/password, etc to connect?

jr_yeo
07-31-2006, 10:23 AM
don't you need the host/user/password, etc to connect?
yupz :p but do i have to post that info here? :D

BLiZZaRD
07-31-2006, 10:29 AM
No, not expecting you too, LMAO... just making sure it was there is all. I usually XXXXX my info like that when I post. I just didn't see the spots for it, so I was just checking :)

jr_yeo
07-31-2006, 10:33 AM
I was just checking
how thoughtful of u :p

BLiZZaRD
07-31-2006, 10:36 AM
LOL... I guess I could ignore questions.. but then you would pass me in the post count :D

jr_yeo
07-31-2006, 10:42 AM
I guess I could ignore questions
questions in other threads, u mean? :p

but then you would pass me in the post count :D
its ok, not competing with anybody's post count.

BLiZZaRD
07-31-2006, 10:44 AM
questions in other threads, u mean? :p
Aye, there are a couple I stay out of, thats for sure.. and Twey will come in and say there are a couple more I should stay out of that I don't. LOL



its ok, not competing with anybody's post count.

LMAO.. nor I buddy... just making a funny :D

jr_yeo
07-31-2006, 10:47 AM
what does LMAO and ROFL mean again? :p

djr33
07-31-2006, 10:49 AM
Now, that, even late, I can answer.
Laughing My ### Off, and Rolling on the floor.... er... ROFL is rolling on floor laughing...

Perhaps...
LMAOROTFLOL?



also, the most important thing is to add <?php instead of just <?. That will be helpful. The run it, upload, and link, and repost the code. Let's see where it stands as of then.
Or, do you not have a database up?

Are you trying to use this, or asking theoretically?
If theoretical, it's a lot simpler to deal with... just explain the logic and be done with it. With doing it, testing is the only way to go.

BLiZZaRD
07-31-2006, 10:50 AM
Perhaps...
LMAOROTFLOL?


Why do people always have to go and complicate simple things? HAHAHAHHAHAA :p

djr33
07-31-2006, 10:52 AM
I'm being sarcastic, but that seems to have no been carried through with the text. Forgive me, I would never say that seriously. (Or, I suppose as fits the "word", jokingly. Heh)

BLiZZaRD
07-31-2006, 10:53 AM
I think your 1:1 smiley to text line ratio was off, and therefore threw me off.

djr33
07-31-2006, 10:57 AM
Ha, alright. :p :D
(see, I made up for it. :))

BLiZZaRD
07-31-2006, 11:05 AM
http://www.cleverwasteoftime.com/forum/Smileys/smiles/lmmfao.gif

This forum needs more smileys...

jr_yeo
07-31-2006, 11:07 AM
also, the most important thing is to add <?php instead of just <?. That will be helpful.
okies. as per requested.


The run it, upload, and link, and repost the code. Let's see where it stands as of then.
sorry. local web server only.


Or, do you not have a database up?
i have the database up and running


Are you trying to use this, or asking theoretically?
going to use 'this' :p

jr_yeo
07-31-2006, 11:09 AM
This forum needs more smileys
yeah, i agree. just like in ym.

BLiZZaRD
07-31-2006, 11:13 AM
You will also need to output the values to the javascript, not just keep them in PHP.
For exaple:
<script>
<?php echo "var = 'value';"; ?>
</script>


Did you separate you php codes from within the JS script?

jr_yeo
07-31-2006, 11:15 AM
Did you separate you php codes from within the JS script?
dont know how to do that with the code that i just posted? :cool:

BLiZZaRD
07-31-2006, 11:34 AM
Now you are mixing JS and php and I will get a headache trying to make a post that even looks like it makes sense. :)

I have no idea either. From what I gater you have JS variables (i=0, for e.g.)

djr was saying you need to make those php as well as js inside the script so the database gets updated when the script needs it too...

or something like that http://www.cleverwasteoftime.com/forum/Smileys/smiles/dunno.gif

jr_yeo
07-31-2006, 11:42 AM
I guess I could ignore questions
couldn't u just ignore the question and let other ppl here to help :p:D:cool: hehe :eek:

BLiZZaRD
07-31-2006, 11:56 AM
But then no one would be around to confuse you...

...fine.. if that's what you want.... :p

jr_yeo
07-31-2006, 12:10 PM
But then no one would be around to confuse you...
...fine.. if that's what you want....
m much confused as it is :p:D:cool:
its not what i want that matters, its what u want :eek:

jr_yeo
07-31-2006, 01:43 PM
any idea guyz on how do i make this work?

djr33
07-31-2006, 07:23 PM
the javascript should do stuff, right?

well... if the php is supposed to relate to that, then it needs to be connected, somehow.
That's what I was saying.

really, I'm still a bit confused as to what's going on as there are some parts missing, and not sure exactly what they are or should be, depending on purpose.

I'm pretty busy... sorry, not trying to ignore you.

jr_yeo
07-31-2006, 07:46 PM
the javascript should do stuff, right?
well... if the php is supposed to relate to that, then it needs to be connected, somehow. That's what I was saying.
i know. but m not at intermediate level at js and php.

really, I'm still a bit confused as to what's going on as there are some parts missing, and not sure exactly what they are or should be, depending on purpose.
ill post the whole code. :)

I'm pretty busy... sorry, not trying to ignore you.
kinda felt that way. but no biggie. apology accepted. i know how busy other people's schedule are but i was just thinking, there are others besides you who could answer my question (shrugs). not that m complaining or something :cool:


<?php // the php side
$query1 = "SELECT $uniquerow, prev_path, filename FROM $tablename";
$rs = mysql_query($query1);
$randomId = array();
while($row = mysql_fetch_array($rs))
array_push($randomId, $row['id']);
$randomId = $randomId[rand(0, count($randomId))]
?>
<head>
<style type="text/css">

#picturearea{
filter:alpha(opacity=100);
-moz-opacity: 0;
}

</style>

<!-- Change path below to point to "getpics.php" on your server -->
<script src="getpics.php" type="text/javascript"></script>
<!-- but i dont want to use getpics.php
maybe i can get data from database to
display instead. -->
<script type="text/javascript">

<!-- Dynamic PHP Picture Viewer (v1.0)- By JavaScriptKit.com (http://www.javascriptkit.com) //--->
<!-- For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/ //--->
<!-- This notice must stay intact for use //--->

function populateSelect(selectobj){
for (var i=0; i<picsarray.length; i++)
selectobj.options[selectobj.options.length]=new Option(picsarray[i], picsarray[i])
if (selectobj.options.length>1){
selectobj.selectedIndex=0
showpicture(document.getElementById("picsform").picslist)
}
}

function showpicture(selectobj){
piccontainerobj=document.getElementById("picturearea")
resetfade(10)
piccontainerobj.innerHTML='<img src="'+locationstring+selectobj.options[selectobj.selectedIndex].value+'">'
fadepictoview=setInterval("gradualfade(piccontainerobj)",50)
}

function resetfade(degree){
if (window.fadepictoview)
clearInterval(fadepictoview)
if (typeof piccontainerobj.style.MozOpacity=="string")
piccontainerobj.style.MozOpacity=degree/100
else if (piccontainerobj.filters)
piccontainerobj.filters.alpha.opacity=degree
}

function gradualfade(){
if (typeof piccontainerobj.style.MozOpacity=="string" && piccontainerobj.style.MozOpacity<1)
piccontainerobj.style.MozOpacity=Math.min(parseFloat(piccontainerobj.style.MozOpacity)+0.2, 0.99)
else if (piccontainerobj.filters && piccontainerobj.filters.alpha.opacity<100)
piccontainerobj.filters.alpha.opacity+=20
else //if not IE or Moz
clearInterval(fadepictoview)
}

window.onload=function(){
populateSelect(document.getElementById("picsform").picslist)
}

</script></head>
<body>
<div style="float: left; width: 200px;">
<form id="picsform">
<select name="picslist" size="4" style="width: 200px" onClick="showpicture(this)">
</select>
</form>
</div>

<div id="picturearea" style="float: left; width: 400px; height: 300px; margin-left: 20px">
</div>

<br style="clear: left" />

<p style="font: normal 11px Arial">This free script provided by<br />
<a href="http://www.javascriptkit.com">JavaScript Kit</a></p>
</body>

djr33
07-31-2006, 07:52 PM
The idea is just fine.
Just use, in getpics.php that original code as a base.
Simply use a different method of getting the pics, but still assign them in the same way.
So... if it's something like:

<?php
function searchforpictures() {
if (file("image.jpg")) {dostuff();}
};
//end part1, start part 2
$image1 = "image.jpg";
?>
Just keep the end, where it's setting the images up for the next page, and just use a database method instead of the file searching / directory searching method (I'm assuming that's what getpics does).
You want the same code in getpics.php, but just a different method of finding the files. Just replace only the code for that particular piece of it.

jr_yeo
07-31-2006, 08:24 PM
Just replace only the code for that particular piece of it.
how do i do that? :p

jr_yeo
07-31-2006, 09:35 PM
is there no else? Twey? jscheuer1? where are u guys?

jr_yeo
08-01-2006, 02:50 PM
never the mind. got it working.

BLiZZaRD
08-01-2006, 07:52 PM
Mind showing an example of what you ended up doing? :)

jr_yeo
08-02-2006, 03:49 AM
Mind showing an example of what you ended up doing? :)
sure. np. i modified the getpics.php script.
getpics.php


<?php
Header("content-type: application/x-javascript");
$pathstring=pathinfo($_SERVER['PHP_SELF']);
$locationstring="http://" . $_SERVER['HTTP_HOST'].$pathstring['dirname'] . "/";

echo 'var locationstring="' . $locationstring . '";' . "\n";
echo 'var imgPath = new Array();' . "\n";
require_once("config.php");
require_once("opendb.php");
$tablename = 'XXXXX';
$uniquerow = 'XXXXX';

$query1 = "SELECT $uniquerow, prev_path, filename FROM $tablename LIMIT 0, 75";
$rs = mysql_query($query1);

$ct = 0;
while($row = mysql_fetch_array($rs))
{
$file = $row['filename'];
echo 'imgPath[' . $ct . '] = ["' . $row['prev_path'] . "/" . $row['filename'] . '", "' . $file . '"];' . "\n";
$ct++;
}?>

main file :)


<html>
<head>
<title>No Title</title>
<style type="text/css">

#picturearea{
filter:alpha(opacity=100);
-moz-opacity: 0;
}

</style>

<script src="getpics.php" type="text/javascript"></script>

<script type="text/javascript">

<!-- Dynamic PHP Picture Viewer (v1.0)- By JavaScriptKit.com (http://www.javascriptkit.com) //--->
<!-- For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/ //--->
<!-- This notice must stay intact for use //--->

function populateSelect(selectobj){
for (var i=0; i<imgPath.length; i++)
selectobj.options[selectobj.options.length]=new Option(imgPath[i][1], imgPath[i][0])
if (selectobj.options.length>1){
selectobj.selectedIndex=0
showpicture(document.getElementById("picsform").picslist)
}
}

function showpicture(selectobj){
piccontainerobj=document.getElementById("picturearea")
resetfade(10)
piccontainerobj.innerHTML='<img src="'+locationstring+selectobj.options[selectobj.selectedIndex].value+'">'
fadepictoview=setInterval("gradualfade(piccontainerobj)",50)
}

function resetfade(degree){
if (window.fadepictoview)
clearInterval(fadepictoview)
if (typeof piccontainerobj.style.MozOpacity=="string")
piccontainerobj.style.MozOpacity=degree/100
else if (piccontainerobj.filters)
piccontainerobj.filters.alpha.opacity=degree
}

function gradualfade(){
if (typeof piccontainerobj.style.MozOpacity=="string" && piccontainerobj.style.MozOpacity<1)
piccontainerobj.style.MozOpacity=Math.min(parseFloat(piccontainerobj.style.MozOpacity)+0.2, 0.99)
else if (piccontainerobj.filters && piccontainerobj.filters.alpha.opacity<100)
piccontainerobj.filters.alpha.opacity+=20
else //if not IE or Moz
clearInterval(fadepictoview)
}

window.onload=function(){
populateSelect(document.getElementById("picsform").picslist)
}

</script>
</head>
<body bgcolor="black" text="white" alink="green" vlink="red" link="blue">
<div style="float: left; width: 200px;">
<form id="picsform">
<select name="picslist" size="<?php echo strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") != false ? "1" : "2"; ?>" onChange="showpicture(this)">
</select>
</form>
</div>

<div id="picturearea" style="float: left; width: 400px; height: 300px; margin-left: 20px">
</div>

<br style="clear: left" />

<p style="font: normal 11px Arial">This free script provided by<br />
<a href="http://www.javascriptkit.com">JavaScript Kit</a></p>
</body>
</html>


guess the next step is figuring out how to use pagination :cool:

BLiZZaRD
08-02-2006, 04:13 AM
Thanks. It all makes perfect sense now... LOL.. errr not. :)

But I can study this a bit.

jr_yeo
08-02-2006, 04:28 AM
But I can study this a bit.
yeah. u do that. :cool:


Thanks. It all makes perfect sense now... LOL.. errr not.
sorry for not putting comments on the scripts. never thought i would be sharing it.

BLiZZaRD
08-02-2006, 07:53 PM
LOL I wasn't asking for comments... I was still confused from the original "put php inside the JS stuff" and was still having a hard time making sense of it all.

I think I get it now though :)

jr_yeo
08-03-2006, 12:33 AM
LOL I wasn't asking for comments...
okies :p m just saying... :cool: