Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-02-2005, 10:14 AM Php and javascript
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
Heey lads i need some help
Have absolutely no clue how to do this but i'm pretty sure it can be done.

I have a database with image locations on my site.
How do i create a javascript for somebody else to include in their site to browse through these images.
(The images which they need to browse through will vary per site which includes the javascript)
I think this requires javascript and php


No clue how to do this, if you guys could point me the way
__________________
Know what to Download

Please login or register to view this content. Registration is FREE
lajkonik86 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-02-2005, 01:22 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
The Javascript "src" can be any type of file, including a .php:
HTML Code:
<script type="text/javascript" src="http://yourserver.com/myscript.php"></script>
So you can use PHP to output real Javascript code, which will then be placed on their site. For example:

myscript.php
PHP Code:
// .. all of your db work
$js '';
while(
$img mysql_fetch_array($res))
{
    
$js .= 'document.write("<img src=\"' $img['img_src'] . '\" alt=\"' $img['info'] . '\" />");';
}

echo 
$js
And to the browser, it will look like valid Javascript:
Code:
document.write("<img src=\"http://yourdomain.com/image.gif\" alt=\"An image\" />");
document.write("<img src=\"http://yourdomain.com/image2.gif\" alt=\"An image 2\" />");
document.write("<img src=\"http://yourdomain.com/image3.gif\" alt=\"An image 3\" />");
That would create 3 images.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 06-02-2005, 01:37 PM
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
as simple as that? sweet

i'm going to use that with a bit of DHTML and have some great scripting fun

Thanks Chroder!
__________________
Know what to Download

Please login or register to view this content. Registration is FREE
lajkonik86 is offline
Reply With Quote
View Public Profile
 
Old 06-02-2005, 08:56 PM
Experienced Talker

Posts: 32
Trades: 0
i am having the same problem. Actualy my pictures are in a folder and i want to use javascript to recognize all the picttures in the folder and makes the next files list such that this file list can be place in a javascript code to displays on site. Bascially i want to know how can i make the php so that it makes the list from a folder Thanks alot guys i really appreciate the help
rcubes85 is offline
Reply With Quote
View Public Profile
 
Old 06-02-2005, 10:13 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Quote:
Originally Posted by lajkonik86
as simple as that? sweet

i'm going to use that with a bit of DHTML and have some great scripting fun

Thanks Chroder!
Yup You should look into caching too, you don't want to be regenerating the same file every time a person requests it. Do an update every X mins or something.

Quote:
Originally Posted by rcubes85
i am having the same problem. Actualy my pictures are in a folder and i want to use javascript to recognize all the picttures in the folder and makes the next files list such that this file list can be place in a javascript code to displays on site. Bascially i want to know how can i make the php so that it makes the list from a folder Thanks alot guys i really appreciate the help
You can use the same technique combined with directory functions. Something like this:
PHP Code:
<?php

$dir        
'./myimages';
$url        'http://mydomain.com/myimages';
$mimetypes  = array('image/gif''image/png''image/jpeg');

///////////////

$dh opendir($dir);
$js '';

while( (
$file readdir($dh)) !== false )
{
    if(
$file == '.' || $file == '..')
        continue;
        
    
$filepath $dir '/' $file;
    if(
is_file($filepath) &&  in_array(mime_content_type($filepath), $mimetypes))
        
$js .= 'document.write("<img src=\"' $url '/' $file '\" />");';   
}

echo 
$js;

?>
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 06-02-2005, 11:58 PM
Experienced Talker

Posts: 32
Trades: 0
sweet thanks alot
rcubes85 is offline
Reply With Quote
View Public Profile
 
Old 06-06-2005, 04:38 AM
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
the javascript is only for customers so it will be low usage and only temporary for testing.
So no need for caching, which would be quite a hassle.

Thanks anyhow
__________________
Know what to Download

Please login or register to view this content. Registration is FREE
lajkonik86 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Php and javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25292 seconds with 12 queries