Page 2 of 2

Posted: Mon May 05, 2003 5:51 am
by []InTeR[]

Code: Select all

echo $comic, '<br /><a href="', $_SERVER&#1111;'PHP_SELF'], '?comic=', $comic, '&funct=2">click</a>';
This is not the error, but why use a , instead of .

EDIT/UPDATE:
To output one or more strings i read it on php.net.

Posted: Mon May 05, 2003 6:07 am
by []InTeR[]
I copied

Code: Select all

<html><body><?php 
$funct = (!empty($_GET['funct'])) ? $_GET['funct'] : 5; 
$comic = (!empty($_GET['comic'])) ? $_GET['comic'] : 3; 

if ($funct == 2) { 
   $comic = $comic - 1; 
   if ($comic < 1) { 
      $comic = 1; 
   } 
} 
echo $comic, '<br /><a href="', $_SERVER['PHP_SELF'], '?comic=', $comic, '&funct=2">click</a>'; 
?></body></html>
But no error's here.
php 4.2.3 @ Linux

Posted: Mon May 05, 2003 6:53 am
by marshie
There's got to be something wrong with the server, or maybe it's not supporting the $funct = (!empty($_GET['funct'])) ? $_GET['funct'] : 5; lines. Is there another way I can do them?

Posted: Mon May 05, 2003 7:00 am
by twigletmac
twigletmac wrote: BTW, doing:

Code: Select all

<?php $funct = (!empty($_GET['funct'])) ? $_GET['funct'] : 5; ?>
is a shorter way of writing:

Code: Select all

<?php
if (!empty($_GET['funct'])) {
    $funct = $_GET['funct'];
} else {
    $funct = 5;
}
?>
and what it does is get the value of funct from the query string in the URL if it's there and if not sets it to a default value of 5 (or whatever you like).

Posted: Mon May 05, 2003 7:10 am
by marshie
Oh yeah. :)

Nope, still no luck. Error on line 15. Here's the code I have now.
<html>
<body>
<table align="left" border="0" cellpadding="10" cellspacing="0">
<tr>
<td>Test1</td>
</tr>
<tr>
<td>Test2</td>
</tr>
</table>

<?php

if (!empty($_GET['funct'])) {
   $funct = $_GET['funct'];
} else {
    $funct = 5;
}

if (!empty($_GET['comic'])) {
    $comic = $_GET['comic'];
} else {
    $comic = 3;
}

if ($funct == 2) {
$comic = $comic - 1;
if ($comic < 1) {
$comic = 1;
}
// use elseif not a separate if for this
} elseif ($funct == 3) {
$comic = $comic + 1;
if ($comic > 3) {
$comic = 3;
}
} elseif ($funct == 4) {
$comic = 3;
} elseif ($funct == 5) {
$comic = 1;
}

echo '<img src="http://members.lycos.co.uk/comicsforpub ... omic.'.jpg">';

<a href="test.php?funct=2&comic=<?php echo $comic; ">back</a>
<a href="test.php?funct=3&comic=<?php echo $comic; ">forward</a>
<a href="test.php?funct=4&comic=<?php echo $comic; ">latest</a>
<a href="test.php?funct=5&comic=<?php echo $comic; ">first</a>
</body>
</html>
There has got to be some way to get this to work. I swear, no matter how long it takes me, I am going to find a way to do this. :P

Posted: Mon May 05, 2003 7:19 am
by marshie
I think I have an idea. How can I say "if ($funct = doesnotexist)" without using that !GET function?

Posted: Mon May 05, 2003 7:22 am
by []InTeR[]
Maybe try:
if (empty($funct)) {
$funct = 5;
}

if (empty($comic)) {
$comic = 3;
}

The $funct is allready set to the $_POST['funct'] content.
So you can check if it's empty or even isset($comic) will do now.

Posted: Mon May 05, 2003 7:38 am
by marshie
Woohoo!! I FINALLY got it!! Check it out. :D
<html>
<?php

$latest = 3;

if (empty($funct)) {
$comic = $latest;
}

if ($funct == 2) {
$comic = $comic - 1;
if ($comic < 1) {
$comic = 1;
}
}

if ($funct == 3) {
$comic = $comic + 1;
if ($comic > 3) {
$comic = 3;
}
}

if ($funct == 4) {
$comic = 1;
}


echo '<img src="http://members.lycos.co.uk/comicsforpub ... omic.'.jpg">';

?>

<a href='test.php?funct=2&comic=<?echo ("$comic")?>'>back</a>
<a href='test.php?funct=3&comic=<?echo ("$comic")?>'>forward</a>
<a href='test.php?comic=<?echo ("$latest")?>'>latest</a>
<a href='test.php?funct=4'>first</a>
</body>
</html>
It works perfectly now! I'm finally done! DONE!! *murders Tripod*

Thanky you all very much for your help, I really really appreciate it. :)