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
How to build a PHPscript that allows you to update Images automatically?
Old 02-27-2008, 09:37 PM How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
I'd like to know how to set up a gallery of images that updates once every 24 hours, and when you click on the picture it will take you to a specific link.

Can anyone tell me where to look to get this script, or how to do it?


thank you,
Lashtal
Lashtal is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-28-2008, 12:50 AM Re: How to build a PHPscript that allows you to update Images automatically?
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
What do you mean with 'updates every 24 hours'? What is an 'update' in your case?
__________________

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

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-28-2008, 01:12 PM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
I mean, the ability to have an image automatically switch to another image (already stored in a particular folder) once every 24 hours.

Say I got this Image right here...

((IMAGE OF TREES AT MY FAVORITE PARK))

How do I build a PHPscript that allows me to have that image automatically change itself to another one once every 24 hours?
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 01:13 PM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
I'm trying to make my gallery auto-updating. And: On A Timer.
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 02:29 PM Re: How to build a PHPscript that allows you to update Images automatically?
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
I am very new to php, so this is a first

How many images? If its more than seven then i'm afraid theres a lot more copying and pasting skip to code 2

Code 1


Just use the time() function and an elseif statement(s). To update it every 24 hours, you could use days.

PHP Code:
<?php
$day
=date("D");

if (
$day=="Mon")
  echo 
'<img src="1.gif" />'
elseif (
$day=="Tue")
  echo 
'<img src="2.gif" />'
elseif (
$day=="Wed")
  echo 
'<img src="3.gif" />'
elseif (
$day=="Thu")
  echo 
'<img src="4.gif" />'
elseif (
$day=="Fri")
  echo 
'<img src="5.gif" />'
elseif (
$day=="Sat")
  echo 
'<img src="6.gif" />'
elseif (
$day=="Sun")
  echo 
'<img src="7.gif" />'
  
?>
Code 2

now this one can only be for 366 images

for the sake of an example, i'll only use 10.

PHP Code:
<?php
$day
=date("WD");

if (
$day=="01Mon")
  echo 
'<img src="1.gif" />'
elseif (
$day=="01Tue")
  echo 
'<img src="2.gif" />'
elseif (
$day=="01Wed")
  echo 
'<img src="3.gif" />'
elseif (
$day=="01Thu")
  echo 
'<img src="4.gif" />'
elseif (
$day=="01Fri")
  echo 
'<img src="5.gif" />'
elseif (
$day=="01Sat")
  echo 
'<img src="6.gif" />'
elseif (
$day=="01Sun")
  echo 
'<img src="7.gif" />'
elseif (
$day=="02Mon")
  echo 
'<img src="8.gif" />'
elseif (
$day=="02Tue")
  echo 
'<img src="9.gif" />'
elseif (
$day=="02Wed")
  echo 
'<img src="10.gif" />'
  
?>
Bare in mind that the above will only work for the first two weeks of jan

Last edited by Gilligan; 02-28-2008 at 02:33 PM..
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 03:39 PM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
How do I make the code select images At Random?

and, how do I get it alternate between an Infinite Number of images; instead of just 366?

thank you very much for your help thus far. I look forward to learning even more, I just can't find what i'm looking for on Google, so I thought i'd ask the masters.
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 03:52 PM Re: How to build a PHPscript that allows you to update Images automatically?
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Better is this:
PHP Code:
<?php $max =10;//Set this to how many images you have.
$d=date("z");
$query "SELECT * FROM `updated`";
$result mysql_query($query);
$l mysql_fetch_array($result);
if(
$d $l[0] || ($d == && $l[0] == 365)){
    
$img rand(1,$max);//If you want to start images with 0 use 0 not 1
    
$query "UPDATE TABLE `updated` SET updated = $d && image = $img where updated= $l[0]";
    
$result $query($query);
    echo 
'<img src="images/'.$img.'.jpg" alt="Daily Image">';
}
else{echo 
'<img src="images/'.$l[1].'.jpg" alt="Daily Image">';}?>
What happens is $max is set to your number of images, which are kept in the folder images which is inside the folder that the script is in. It then gets the date, and the date last updated from a mysql table which has only two columns and one row in it, the first column is `updated` and it holds the day of the year that it is, the second contains the daily image. If it's a new day since the script last executed it'll then choose a random image eg (images/1.jpg or images/2.jpg) and display, and it'll update the table with the new updated date and the new image, if it's not a new day it'll skip all that and just output the daily image.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 02-28-2008, 06:31 PM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Alright.
Let me start off by saying that i'm using Windows Vista, and i'm trying to send this Script to my webhost at GoDaddy.com

I went to MySQL, and I tried to Import the following Script:

"<?php $max =10;//Set this to how many images you have.
$d=date("z");
$query = "SELECT * FROM `updated`";
$result = mysql_query($query);
$l = mysql_fetch_array($result);
if($d > $l[0] || ($d == 0 && $l[0] == 365)){
$img = rand(1,$max);//If you want to start images with 0 use 0 not 1
$query = "UPDATE TABLE `updated` SET updated = $d && image = $img where updated= $l[0]";
$result = $query($query);
echo '<img src="images/'.$img.'.jpg" alt="Daily Image">';
}
else{echo '<img src="images/'.$l[1].'.jpg" alt="Daily Image">';}?>"

But I received an error message, Error #1064
saying that it cannot read specfically the punctuation "<?php"

So I am very confused...

Last edited by Lashtal; 02-28-2008 at 09:14 PM..
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 09:36 PM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Here is the error message I get...

ERROR
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

ERROR: Unknown Punctuation String @ 1
STR: <?
SQL: <?php
$max =10;

SQL query:

MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php
$max =10' at line 1

Last edited by Lashtal; 02-28-2008 at 09:40 PM..
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 10:01 PM Re: How to build a PHPscript that allows you to update Images automatically?
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
That is PHP not just MySQL both $query are SQL statements.
Code:
CREATE TABLE updated(updated int(11),image int(11);
INSERT INTO `updated` values(0,1);
Run that and it'll create the table them populate it with an entry. Put the PHP into a page and edit anything you need to (such as $max or where your images are held) and make sure you have the images made and then run that page, it should output a random image. Also you'll need to connect to MySQL before hand so after the <?php but before $query put these lines in and customize them:
PHP Code:
$link mysql_connect('localhost''mysql_user''mysql_password') or die("Could not connect: ".mysql_error());
$db_select mysql_select_db('db_name',$link) or die("Could not select: ".mysql_error()); 
Add this line right before the ?>
PHP Code:
mysql_close($link); 
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 02-29-2008, 03:48 AM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
How do I assign specific links to each image with this code?

and

How can I modify it to display .gif images as well?
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 02-29-2008, 10:53 AM Re: How to build a PHPscript that allows you to update Images automatically?
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
If no one else grabs this I'll get to it tonight.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 03-02-2008, 04:22 PM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Please?
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 03-04-2008, 10:24 PM Re: How to build a PHPscript that allows you to update Images automatically?
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Sorry it took so long to get around to this, had a very insane past few days. The way this works is we're going to create a second table that is the following:
Code:
CREATE TABLE images(image int(11) primary key auto_increment, name varchar(40) unique, link text);
This will make a new table that has three columns in it, the first column is named image and is the number of the image as used in the PHP code I gave you the first time around. The second column is the name of the image, blah.gif or null.jpg, the image names all must be unique. The third column is the link for the image.
Instead of the PHP used above we will be using a new script:
PHP Code:
<?php $link mysql_connect('localhost''mysql_user''mysql_password') or die("Could not connect: ".mysql_error());
$db_select mysql_select_db('db_name',$link) or die("Could not select: ".mysql_error());
$max =10;//Set this to how many images you have.
$d=date("z");
$query "SELECT * FROM `updated`";
$result mysql_query($query);
$l mysql_fetch_array($result);
if(
$d $l[0] || ($d == && $l[0] == 365)){
    
$img rand(1,$max);
    
$query "UPDATE TABLE `updated` SET updated = $d && image = $img where updated= $l[0]";
    
$result mysql_query($query);
    
$query "SELECT * FROM `images` where image=$img";
    
$result mysql_query($query);
    
$array mysql_fetch_array($result);
    echo 
'<a href="'.$array[2].'"><img src="images/'.$array[1].'" alt="Daily Image"></a>';
}
else{
$query "SELECT * FROM updated, images WHERE updated.image = images.image";
    
$result mysql_query($query);
    
$array mysql_fetch_array($result);
    echo 
'<a href="'.$array[4].'"><img src="images/'.$array[3].'" alt="Daily Image"></a>';}
mysql_close($link);?>
Make sure to run this SQL command too if you haven't already:
Code:
CREATE TABLE updated(updated int(11),image int(11));
INSERT INTO `updated` values(0,1);
All you have to do to insert a new picture is run this SQL changing IMAGE_NAME for the image's name and LINK_LOCATION to the link (including http://) DO NOT REMOVE THE QUOTES!!:
Code:
INSERT INTO `images` VALUES(NULL,'IMAGE_NAME','LINK_LOCATION');
An example of this would be:
Code:
INSERT INTO `images` VALUES(NULL,'blah.png','http://example.com');
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 03-05-2008, 04:36 AM Re: How to build a PHPscript that allows you to update Images automatically?
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
So I managed to successfully create the tables.

I was even able to successfully add more images to the desired 'images' table.

But I am confused about what to do with the PHPscript itself.

Do I insert it into wordpad and save it as ".php", then upload it to my 'images' table?

Or do I just insert it into my webpage?


This is my first time executing a PHPscript, so please remember that you're speaking to a newbie here

And thank you so far, for a lot of your help!
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE

Last edited by Lashtal; 03-06-2008 at 03:00 AM..
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 03-06-2008, 09:24 PM Re: How to build a PHPscript that allows you to update Images automatically?
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
PHP is inserted in a webpage. An example woudl be:
HTML Code:
<html><head><title>Hello World</title></head><body><?php echo "<p>Hello World</p>";?></body></html>
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Reply     « Reply to How to build a PHPscript that allows you to update Images automatically?
 

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.53832 seconds with 12 queries