funhyun1
asked on
Need help editing an script that I downloaded
Hi Experts,
I need help in modifying this great phpphotoslideshow script from http://www.zinkwazi.com/wp/scripts/ . I had installed it on my testing area. You can view it at http://www.pdim.net/phpslideshow/phpslideshow.php for its progress.
I need to modify the script to do as follows:
1) When the user clicks on the next button, a random image appears but without repeating until the whole set of images are shown at least once. (ex: if there are 30 images in the slide show, the user should able to view it randomly from 1-30 without any images being viewed repeted times. After the 30th image viewed, the random show starts again.)
2) If you click on "Company: Links", the hyperlink does not go where I specified as in the pics.txt file. Instead, it goes to a unknown page. I would like it to go to the intended page.
If you like, you can download the entire files from http://pdim.net/phpslideshow/phpslideshow.zip to dig under the hood. If need be I will assign more points to this questions. Thanks in advance!!!!!!!
I need help in modifying this great phpphotoslideshow script from http://www.zinkwazi.com/wp/scripts/ . I had installed it on my testing area. You can view it at http://www.pdim.net/phpslideshow/phpslideshow.php for its progress.
I need to modify the script to do as follows:
1) When the user clicks on the next button, a random image appears but without repeating until the whole set of images are shown at least once. (ex: if there are 30 images in the slide show, the user should able to view it randomly from 1-30 without any images being viewed repeted times. After the 30th image viewed, the random show starts again.)
2) If you click on "Company: Links", the hyperlink does not go where I specified as in the pics.txt file. Instead, it goes to a unknown page. I would like it to go to the intended page.
If you like, you can download the entire files from http://pdim.net/phpslideshow/phpslideshow.zip to dig under the hood. If need be I will assign more points to this questions. Thanks in advance!!!!!!!
ASKER
Hi Fibo,
Thanks for your amazing help! My #2 question is clear but I am still having difficulty understanding your suggestion on my q #1. So that you know, my skill level in PHP is not so good therefore you have to walk me through the process of change my code to randomizing. Please advise where (which lines?) I should delete and replace/add your new codes? Thanks again for helping and bearing.
Thanks for your amazing help! My #2 question is clear but I am still having difficulty understanding your suggestion on my q #1. So that you know, my skill level in PHP is not so good therefore you have to walk me through the process of change my code to randomizing. Please advise where (which lines?) I should delete and replace/add your new codes? Thanks again for helping and bearing.
Looking at the file, I guess that the best place to put your changes would be around line 149 of phpslideshow.php:
if ($sort_images == 'name') {
natcasesort($pic_info);
$pic_info = array_reverse(array_revers e($pic_inf o)); //resetting array keys
}
else {
$sortorder = $sort_images == "oldest" ? SORT_ASC : SORT_DESC;
array_multisort($time_info , $sortorder, $pic_info, SORT_ASC, $time_info);
}
I would probably change these line to create the correct arrays. the only line to keep would be (using "my" $ind array)
array_multisort($ind, $pic_info, $time_info)
Sorry, it's late, I need some sleep.
Cheers
if ($sort_images == 'name') {
natcasesort($pic_info);
$pic_info = array_reverse(array_revers
}
else {
$sortorder = $sort_images == "oldest" ? SORT_ASC : SORT_DESC;
array_multisort($time_info
}
I would probably change these line to create the correct arrays. the only line to keep would be (using "my" $ind array)
array_multisort($ind, $pic_info, $time_info)
Sorry, it's late, I need some sleep.
Cheers
ASKER
Hope you got some good rest. Ok here is what i did. I changed lines 149-156
from:
if ($sort_images == 'name') {
natcasesort($pic_info);
$pic_info = array_reverse(array_revers e($pic_inf o)); //resetting array keys
}
else {
$sortorder = $sort_images == "oldest" ? SORT_ASC : SORT_DESC;
array_multisort($time_info , $sortorder, $pic_info, SORT_ASC, $time_info);
}
and replaced it with
$ind=array();
$imax=30;
for ($i=0; $i<imax;i++) $ind[]=$i;
for ($i=0; $i<($imax-1);i++) { // note that here it is 29, not 30
$k=rand(($i+1),$imax);
$tmp=$ind($k);
$ind($k)=$ind($i);
$ind($i)=$tmp;
} //done
and I get this error:
Parse error: parse error, unexpected T_INC, expecting ')' in /home/pdimnet/public_html/ phpslidesh ow/phpslid eshow.php on line 152
Thanks.
from:
if ($sort_images == 'name') {
natcasesort($pic_info);
$pic_info = array_reverse(array_revers
}
else {
$sortorder = $sort_images == "oldest" ? SORT_ASC : SORT_DESC;
array_multisort($time_info
}
and replaced it with
$ind=array();
$imax=30;
for ($i=0; $i<imax;i++) $ind[]=$i;
for ($i=0; $i<($imax-1);i++) { // note that here it is 29, not 30
$k=rand(($i+1),$imax);
$tmp=$ind($k);
$ind($k)=$ind($i);
$ind($i)=$tmp;
} //done
and I get this error:
Parse error: parse error, unexpected T_INC, expecting ')' in /home/pdimnet/public_html/
Thanks.
You are missing a $ in this line:
for ($i=0; $i<imax;i++) $ind[]=$i;
^ (should be $imax)
for ($i=0; $i<imax;i++) $ind[]=$i;
^ (should be $imax)
oops. thx kamermans!
ASKER
Thanks fellas. I tried it and I get this error.
Parse error: parse error, unexpected T_INC, expecting ')' in /home/pdimnet/public_html/ phpslidesh ow/phpslid eshow.php on line 151
Parse error: parse error, unexpected T_INC, expecting ')' in /home/pdimnet/public_html/
Oops. Sorry, I did write the code late at night and gorgot most of the $
Here are the correct lines:
$ind=array();
$imax=30;
for ($i=0; $i<$imax;$i++) $ind[]=$i;
for ($i=0; $i<($imax-1);$i++) { // note that here it is 29, not 30
$k=rand(($i+1),$imax);
$tmp=$ind($k);
$ind($k)=$ind($i);
$ind($i)=$tmp;
} //done
(there were missing $ in both $i++)
Here are the correct lines:
$ind=array();
$imax=30;
for ($i=0; $i<$imax;$i++) $ind[]=$i;
for ($i=0; $i<($imax-1);$i++) { // note that here it is 29, not 30
$k=rand(($i+1),$imax);
$tmp=$ind($k);
$ind($k)=$ind($i);
$ind($i)=$tmp;
} //done
(there were missing $ in both $i++)
ASKER
A different error this time.
Parse error: parse error, unexpected '=' in /home/pdimnet/public_html/ phpslidesh ow/phpslid eshow.php on line 155
Hmm.
Parse error: parse error, unexpected '=' in /home/pdimnet/public_html/
Hmm.
1/ If you used copy/paste, this might have created invisible problems (I think I remember seeing such a problem here), so let's try to remove that: delete then retype "new lines" and spaces or tabs at the beginning of each line.
2/ if the problem is stll there: can you copy/ paste it here, so that we can examine further?
2/ if the problem is stll there: can you copy/ paste it here, so that we can examine further?
ASKER
Hi Fibo,
Here are the codes. You can download from http://www.pdim.net/phpslideshow/phpslideshow-codes.zip . It contains. the original codes and the edited code we are working on. Thanks!
Here are the codes. You can download from http://www.pdim.net/phpslideshow/phpslideshow-codes.zip . It contains. the original codes and the edited code we are working on. Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes! It is working now. However, the slidehow is not random only sequential as before. For your efforts, I give you the points anyway. You can see the slide show at at http://pdim.net/phpslideshow/phpslideshow.php . Let me know if you want to continue in helping me I feel this help is worth more than 500pts therefore I will open up a new thread for more points opportunity. Thnaks.
Thx for the points.
Hmmm... it is sequential, but the sequence is random. You'll get each and every slide in the set, but each time in a different order: the program "shuffles" the sequence as you would do with a deck of cards.
If you just need a single slide at random, you can display the slide numbered rand(0,$imax).
However, in some occasions you might get something like slides 5, 18, 5, 4, 18 which will not be felt as random by yout viewer.
The programs as written "guararntees" (well, almost) that each visit will show the slides in a different order.
Hmmm... it is sequential, but the sequence is random. You'll get each and every slide in the set, but each time in a different order: the program "shuffles" the sequence as you would do with a deck of cards.
If you just need a single slide at random, you can display the slide numbered rand(0,$imax).
However, in some occasions you might get something like slides 5, 18, 5, 4, 18 which will not be felt as random by yout viewer.
The programs as written "guararntees" (well, almost) that each visit will show the slides in a different order.
1- Basically you have an array of 30 records, each with a picture and some additional info: company name, link, etc.
What you have already built is a way to navigate thru record[0], record[1], ... record[29].
Now figure an ind array, the values of which are initially 0 for ind[0]...n for ind[n]... 29 for ind[29]
You just need to "shuffle" the values of this array, and then you're done, you'll be able to navigate it thru record[$ind[0]], ... record[$ind[n]]... record[$ind[29]]
Now the shuffle part. The correct algorithm is :
$ind=array();
$imax=30;
for ($i=0; $i<imax;i++) $ind[]=$i;
for ($i=0; $i<($imax-1);i++) { // note that here it is 29, not 30
$k=rand(($i+1),$imax);
$tmp=$ind($k);
$ind($k)=$ind($i);
$ind($i)=$tmp;
} //done