Shoutbox

Can someone edit this script? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Can someone edit this script? (/showthread.php?tid=41210)

Can someone edit this script? by .Roy on 03-26-2005 at 12:12 PM

<?
$num = $_GET['num'];
if(!isset($_GET['num'])){
$num = "1";
}
?>
<img src="http://www.hobbes.weirdfish.net/strips/strip<?echo $num;?>.jpg" alt="strip<?echo $num;?>.jpg error">

<a href="http://hobbes.weirdfish.net/strip.php?num=<?echo $num+1;?>">Foward</a>
<a href="http://hobbes.weirdfish.net/strip.php?num=<?echo $num-1;?>">Back</a>

Wel can someone edit this script so the smallest number is 1 and it cant go any lower. And it cant go higher then the images i have. I want it to auto detect the last one.


RE: Can someone edit this script? by Plik on 03-26-2005 at 12:15 PM

To do that you would need a way to count how many images you have, so no one can edit your script to do that until they know how your images are saved.


RE: RE: Can someone edit this script? by Ash_ on 03-26-2005 at 12:16 PM

quote:
Originally posted by Madman
To do that you would need a way to count how many images you have, so no one can edit your script to do that until they know how your images are saved.


*cough* scandir() *cough*
RE: Can someone edit this script? by .Roy on 03-26-2005 at 12:44 PM

strip1.jpg
strip2.jpg
strip3.jpg

and so forth.
but i every day i add another one. so i dont want to edit this script every day.


RE: RE: Can someone edit this script? by Ash_ on 03-26-2005 at 01:19 PM

quote:
Originally posted by Hobbes
strip1.jpg
strip2.jpg
strip3.jpg

and so forth.
but i every day i add another one. so i dont want to edit this script every day.

seriosuly dude, code it yourself ¬¬, i thoguht you were learning PHP anyway. think of this as a test.
RE: Can someone edit this script? by Plik on 03-26-2005 at 01:21 PM

Blah i should have been able to work that our myself :dodgy:
anyway this should work, although i havnt tested it.

code:
<?
$num = $_GET['num'];
if(!isset($_GET['num']) OR $num < 1){ //If the input is less than one correct it
$num = "1";
}
?>
<img src="http://www.hobbes.weirdfish.net/strips/strip<?echo $num;?>.jpg" alt="strip<?echo $num;?>.jpg error">
<?php
//first we count the files in the strips
$files = scandir("strips");
$fileno = count($files) - 2;//ignore the . and .. entries
if($num != $fileno){//If we are on the last line dont echo a link other wise do
echo "<a href=\"http://hobbes.weirdfish.net/strip.php?num=" . $num+1 . "\">Foward</a>";
}
if($num > 1){ //check to see if the number is greater than one, if so echo the back link
echo "<a href=\"http://hobbes.weirdfish.net/strip.php?num=" . $num-1 . "\">Back</a>";
}
//other wise just dont echo anything
?>

But as ash said you should try and work these things out for yourself.
http://www.php.net will become your bibble :p
RE: Can someone edit this script? by -dt- on 03-26-2005 at 01:30 PM

quote:
Originally posted by Ash_
when echo. you should use the "s use ' otherwise it causes errors :cheesy:
err wtf? you can use " and ' in echo? =/
RE: RE: Can someone edit this script? by Ash_ on 03-26-2005 at 01:31 PM

quote:
Originally posted by -dt-
quote:
Originally posted by Ash_
when echo. you should use the "s use ' otherwise it causes errors :cheesy:
err wtf? you can use " and ' in echo? =/

lol i know, but using " for the whole echo, and ' for stuff inside the echo will make it easier in the long run :P.
RE: Can someone edit this script? by Plik on 03-26-2005 at 01:33 PM

quote:
Originally posted by Ash_
lol i know, but using " for the whole echo, and ' for stuff inside the echo will make it easier in the long run :P.

or you escape the "s like i did :-/ it all depends on how you want the output to look.
RE: Can someone edit this script? by -dt- on 03-26-2005 at 01:35 PM

quote:
Originally posted by Ash_
lol i know, but using " for the whole echo, and ' for stuff inside the echo will make it easier in the long run :P.

depends what happens if you just want pure text in the varible? (and dont feel like using <<<x   x; )
RE: Can someone edit this script? by .Roy on 03-26-2005 at 01:48 PM

ok madman thanks for the script ill try it out now!

Edit:
Fatal error: Call to undefined function: scandir() in /home/hobbes/public_html/strip.php on line 10


RE: Can someone edit this script? by Plik on 03-26-2005 at 01:50 PM

Im guessing your host doesnt have php 5 installed. Can you confirm this?


RE: Can someone edit this script? by .Roy on 03-26-2005 at 01:52 PM

Ill ask my host now

edit: No it doesnt support php5. Maybe u can do it with another version of php?
edit # 2: PHP Version 4.3.10


RE: RE: Can someone edit this script? by Plik on 03-26-2005 at 01:57 PM

quote:
Originally posted by Hobbes
Ill ask my host now

edit: No it doesnt support php5. Maybe u can do it with another version of php?

Done
code:
<?php
if(!isset($_GET['num']) OR $_GET['num'] < 1){//If the input is less than one correct it
$num = "1";
}
else{
$num = $_GET['num'];//Only use the get varible if it exists or is >1
}
?>
<img src="http://www.hobbes.weirdfish.net/strips/strip<?echo $num;?>.jpg" alt="strip<?echo $num;?>.jpg error" /><br />
<?php
//first we count the files in the strips
$fileno = count_files("strips");
if($num < $fileno){//If we are on the last line dont echo a link other wise do
$next = $num + 1;
echo "<a href=\"http://hobbes.weirdfish.net/strip.php?num=" . $next  . "\">Forward</a> - ";
}
if($num > 1){//check to see if the number is greater than one, if so echo the back link
$prev = $num - 1;
echo "<a href=\"http://hobbes.weirdfish.net/strip.php?num=" . $prev . "\">Back</a>";
}
//other wise just dont echo anything

//file counting function
function count_files($dir){
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
$filesnum = count($files);
return $filesnum;
}
?>



RE: Can someone edit this script? by .Roy on 03-26-2005 at 02:01 PM

Still an error

Parse error: parse error, unexpected T_STRING in /home/hobbes/public_html/strip.php on line 21


RE: Can someone edit this script? by Plik on 03-26-2005 at 02:03 PM

i made a typo on function :banana:
i edited my post and fixed it


RE: Can someone edit this script? by .Roy on 03-26-2005 at 02:04 PM

Hmm thanks but..   http://hobbes.weirdfish.net/strip.php
well see for yourself :D. Maybe you should test it :D


RE: Can someone edit this script? by Plik on 03-26-2005 at 02:23 PM

Ive updated it fixing the bug and making it look not so dodgy with the links on a new line and a - seperating them.


RE: Can someone edit this script? by .Roy on 03-26-2005 at 02:23 PM

"hopefully this works" one second

edit: Works great! Now ill edit how it looks and stuff :D
Thanks Madman. BTW where did u learn html from?
edit #2: Actually when i get over 35 everyone is missing. Because 35 for now is the last one. Can u make it auto detect which is the last one. Like you did with the first one being 1


RE: Can someone edit this script? by Plik on 03-26-2005 at 02:27 PM

Started from a learn to program for dummies book, then from http://www.w3schools.com and i learnt php by looking at others code and from http://www.php.net

quote:
Originally posted by Hobbes
edit #2: Actually when i get over 35 everyone is missing. Because 35 for now is the last one. Can u make it auto detect which is the last one. Like you did with the first one being 1

Updated it again
RE: Can someone edit this script? by .Roy on 03-26-2005 at 02:32 PM

look at my edited post. It still has a bug i think


RE: Can someone edit this script? by segosa on 03-26-2005 at 07:32 PM

code:
function count_files($dir){
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
$filesnum = count($files);
return $filesnum;
}


Couldn't you just make that...

code:
function count_files($dir)
{
    $dh=opendir($dir);
    for($i=0;readdir($dh);$i++);
    return $i-2;
}



RE: Can someone edit this script? by Plik on 03-26-2005 at 08:00 PM

quote:
Originally posted by Segosa
code:
function count_files($dir){
$dh = opendir($dir);
$files = array();
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
array_splice($files, 0, 2);
$filesnum = count($files);
return $filesnum;
}


Couldn't you just make that...

code:
function count_files($dir)
{
    $dh=opendir($dir);
    for($i=0;readdir($dh);$i++);
    return $i-2;
}



Yeh, i just coppied it from another script that needs to acces the files afterwards, with out thinking about editing it down.
RE: Can someone edit this script? by segosa on 03-26-2005 at 08:12 PM


quote:
Originally posted by Madman

Yeh, i just coppied it from another script that needs to acces the files afterwards, with out thinking about editing it down.

Oh, ok.. I managed to get it even more compact :p

code:
function count_files($d)
{
  for($x=opendir($d),$i=0;readdir($x);$i++);
  return $i-2;
}