Thanks Nick! I'm currently working on getting my pets up to snuff, but this helped a lot!
This is my new adoptable site. It's just using the main switch-your-animals-out approach, but heck, it works.
<?php
//Tell the browser that we are sending it a PNG image to display
//header("Content-Type: image/png");
//Echo the contents of the image file called "Alex.png" to send it to the browser
//readfile("Alex.png");
?>
Taija wrote:I have a problem with the codes in the tutorial.
The first code works, but when I extended the code to the baby rats, I get an error message that the code is flawed, and this error message I get when all of the following codes.
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Code -->
<?php
//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");
//Echo the contents of the image file called "dogbaby.png" to send it to the browser
readfile("dogbaby.png");
?>
<?php
//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");
if ($_REQUEST['id']==1) {
//Echo the contents of the image file called "dogbaby.png" to send it to the browser
readfile("dogbaby.png");
} else if ($_REQUEST['id']==2) {
//Echo the contents of the image file called "ratbaby.png" to send it to the browser
readfile("ratbaby.png");
}
?>
Turquoise wrote:Taija wrote:I have a problem with the codes in the tutorial.
The first code works, but when I extended the code to the baby rats, I get an error message that the code is flawed, and this error message I get when all of the following codes.
I was just about to say that SAME thing, how ironic... I use 000webhost, and this is the message I get:
- Code: Select all
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Code -->
You see, When I used this code:
- Code: Select all
<?php
//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");
//Echo the contents of the image file called "dogbaby.png" to send it to the browser
readfile("dogbaby.png");
?>
dogbaby.png showed up JUST fine. I wasn't having any problems.
But once I uploaded new new simple.php and ratbaby, I got that error message (showed above).
Here is the code where the error message first started showing up:
- Code: Select all
<?php
//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");
if ($_REQUEST['id']==1) {
//Echo the contents of the image file called "dogbaby.png" to send it to the browser
readfile("dogbaby.png");
} else if ($_REQUEST['id']==2) {
//Echo the contents of the image file called "ratbaby.png" to send it to the browser
readfile("ratbaby.png");
}
?>
And so that code, and any code I tried after it made that error message to show up.
I'm not sure what's going on here. =P
Turquoise wrote:And so that code, and any code I tried after it made that error message to show up.
I'm not sure what's going on here. =P
Nick wrote:Turquoise wrote:And so that code, and any code I tried after it made that error message to show up.
I'm not sure what's going on here. =P
You're not using the right URL to view the image. As the text says, you need to view simple.php?id=1 or simple.php?id=2, not just simple.php.
<html>
<head>
</head>
<body>
<?php
require("adopttools.php");
/* Our visitor has picked an adoptable they want, its id is in $_REQUEST['id']. Find that
* adoptable in adoptables.xml
*/
$adoptable=find_adoptable($_REQUEST['id']);
/* To randomly pick a variation from that adoptable, we're going have to do a little maths with
* random numbers.
*
* First we find the sum of all the 'chance' attributes for this adoptable...
*/
$sum=0;
foreach ($adoptable->variation as $variation) {
$sum=$sum + $variation['chance'];
}
/* Now we can generate a random number which goes from 0.0 to that sum. This will help us
* pick a variation.
*/
$random=lcg_value()*$sum;
$sum=0;
foreach ($adoptable->variation as $variation) {
$sum = $sum + $variation['chance'];
if ($random <= $sum) {
//Choose this variation
$v_id=$variation['id'];
break;
}
}
?>
<p><img src="simple.php?a=<?php echo $_REQUEST['id'];?>&v=<?php echo $v_id;?>"></p>
<p>Thanks for adopting this pet! :). Here is the adoption code for your pet:</p>
<p><textarea cols="60" rows="2"><img src="http://www.mywebsite.com/simple.php?a=<?php echo $_REQUEST['id'];?>&v=<?php echo $v_id;?>"></textarea></p>
</body>
</html>
<?php
//Load the adoptables XML file
$adoptxml=simplexml_load_file("adoptables.xml");
//Find the adoptable from adoptables.xml which has the right id
function find_adoptable($id) {
global $adoptxml;
//For each 'adoptable' tag which is available
foreach ($adoptxml->adoptable as $adoptable) {
//Is this adoptable's id the same as the one that the user wants to see?
if ($adoptable['id']==$id) {
//Yes, it is
return $adoptable;
}
}
return NULL; //We couldn't find an adoptable with that ID
}
//Find the variation with the given adoptable id and variation id
function find_variation($adoptid, $varid) {
$adoptable=find_adoptable($adoptid);
//For each 'variation' tag which is available
foreach ($adoptable->variation as $variation) {
//Is this variation's id the same as the one that the user wants to see?
if ($variation['id']==$varid) {
//Yes, it is
return $variation;
}
}
return NULL; //We couldn't find the variation with that ID
}
?>
<adoptables>
<adoptable id="1">
<variation id="1" chance="1.0">
<age image="dogbaby.png" />
<age date="2010-1-15" image="dogpuppyrare.png" />
<age date="2010-1-16" image="dogadultrare.png" />
</variation>
<variation id="2" chance="5.0">
<age image="dogbaby.png" />
<age date="2010-1-14" image="dogpuppy.png" />
<age date="2010-1-16" image="dogadult.png" />
</variation>
</adoptable>
<adoptable id="2">
<variation id="1" chance="1.0">
<age image="ratbaby.png" />
<age date="2010-1-15" image="ratadult.png" />
</variation>
</adoptable>
</adoptables>
Users browsing this forum: TANKMEN and 2 guests