<?php
echo "<img src=$id.gif>";
?>
if ($id == 0) {
$id = 1;
}
<?php
// If no ID is specified, use a default.
if ($id == 0) {
$id = 1;
}
// Print the image.
echo "<img src=$id.gif>";
?>
<?php
echo "<title>Picture No. $id</title>";
?>
<?php
// Determine Variables
$next_id = $id + 1;
$prev_id = $id - 1;
// Print Link(s)
echo "<a href=$php_self?id=$next_id>Next Image</a>;"
echo " | ";
echo "<a href=$php_self?id=$prev_id>Previous Image</a>;"
?>
<?php
// If no ID is specified, use a default.
if ($id == 0) {
$id = 1;
}
// Print the image.
echo "<img src=C:\WINDOWS\Desktop\mysite\bspics\BSpics\$id.jpg>";
?>
<?php
// Determine Variables
$next_id = $id + 1;
$prev_id = $id - 1;
// Print Link(s)
echo "<a href=$php_self?id=$next_id>Next Image</a>;"
echo " | ";
echo "<a href=$php_self?id=$prev_id>Previous Image</a>;"
?>
Originally posted by Woofcat
This should do the same thing more safely and efficiently. Note that you probably don't want the img src to point to your desktop...
<?$id=empty($id)?1:floor($id)?>
<img src="C:\WINDOWS\Desktop\mysite\bspics\BSpics\<?=$id?>.jpg">
<a href="<?=$PHP_SELF?>?id=<?=$id+1?>">Next Image</a>
|
<a href="<?=$PHP_SELF?>?id=<?=$id-1?>">Previous Image</a>
Originally posted by coolguy23
i tried it but it says there is an error in line 21...can you help
Code:<?php // If no ID is specified, use a default. if ($id == 0) { $id = 1; } // Print the image. echo "<img src=C:\WINDOWS\Desktop\mysite\bspics\BSpics\$id.jpg>"; ?> <?php // Determine Variables $next_id = $id + 1; $prev_id = $id - 1; // Print Link(s) echo "<a href=$php_self?id=$next_id>Next Image</a>"; echo " | "; echo "<a href=$php_self?id=$prev_id>Previous Image</a>"; ?>
please tell me the exact code i should save in the file
here it is
cgi-bin.spaceports.com/~bsvsca/display.php
...Just wondering (i'm a bit new to php)... what does this line do?:
$id=empty($id)?1:floor($id)
...ignore this post if its a dumb question
Using a variable's contents as a variable's name is a bad idea for many reasons. Read Mark-Jason Dominus's articles at http://perl.plover.com/varvarname.html for more information. They're on the topic of Perl, but PHP has the same problem AFAIK. A good quote: "The real problem is that $$fields = ... is not confined at all, and if something goes wrong, it can smash any variable in the entire program, which will have a bizarre effect, possibly on something far away. "Originally posted by BillWill
A variable variable is something complety different.
Lets say you had a variable named pizza which equals cheese:
$pizza = "cheese";
You could use the text in the pizza variable and make it into a variable:
$$pizza
Resulting in a variable named cheese ($cheese).
That's a variable variable. =)