Rolly-chan wrote:1) I seem to have a problem with the second adoptables system (I copied the first one and edited it so that I could use it on other adoptables - I don't want to have them all in one big xml-file). It works fine BUT sometimes the picture doesn't display. Not always, only sometimes even though I have only ONE variation. That's kinda strange.
I cannot load your website at the moment, it just times out. I suspect that your host which you share with many other customers is overloaded at the moment.
2) I want to upgrade my adoptables system. Yeah, I already activated the MySQL database and created a table with ID and date. I also know how to store the date there... and I kind of have an idea how to do this but I don't really know how. And I don't need a detailed explanation, just a cause for thought ^^
-> Can I use php-codes in the xml file?
No, it's just XML, nothing more. Why would you want to put PHP code there?
And if I can... HOW do I modify the date from the database? I know of date("Y-m-d", strtotime(+ 1 week 2 day) ) for example. But I can't use variables in "date".
Are you trying to store the adoption date of each pet..? If you're storing a date in the database, you'll be using SQL to modify the date, nothing on the PHP end except for calling mysql_query to run the SQL. For instance, if you have a table with this structure:
- Code: Select all
CREATE TABLE `pets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`adoptdate` datetime NOT NULL,
PRIMARY KEY (`id`)
)
Then you could insert a new row with:
- Code: Select all
mysql_query("INSERT INTO pets (adoptdate) VALUES (NOW())");
The ID number of the newly inserted row can then be found by calling:
- Code: Select all
echo "Your new pet's ID: ".mysql_insert_id();
You can get the adoption date for a given pet by:
- Code: Select all
$petid=(int) $_REQUEST['petid']; // Get the ID of the pet passed in the URL. _Make sure that it is a number_ (by casting it to int)
$result=mysql_query("SELECT adoptdate, UNIX_TIMESTAMP(adoptdate) FROM pets WHERE id=$petid");
$row=mysql_fetch_row($result);
echo "Your pet was adopted on ". $row[0];
That UNIX_TIMESTAMP(adoptdate) field gives you the adoption date in PHP's 'time' format. This allows you to format it however you like using PHP's functions, or compare it with PHP date/times. It also allows you to do this:
- Code: Select all
$age=(time()-$row[1])/86400;
echo "Your pet is $age days old";
(86400 is the number of seconds in a day)
And another question (yesh, I know I'm annoying...): When I connect to the database I have to write down my password. Is it safe to do so? o_O Can't someone else look it up then? I can't seem to find any tutorial where this is said...
It's safe, since when you point your browser at your PHP file, you don't (and can't) see the code. You only see what the PHP code chooses to print out. However, if one day your webhost accidentally turns off PHP, visitors will see your code (and your password) instead of the PHP page running correctly. This would be very rare, but you can avoid this problem altogether. When you upload files, you can upload them to a folder which makes them appear at the root of your site, but on many hosts you can
also upload them to the folder
above that, where people cannot see (since it is above the root of your site). You could upload a file there called databasepassword.php, and put this in it:
- Code: Select all
<?php $dbpassword="mypasswordhere"; ?>
Then when you need to connect to the database, you can:
- Code: Select all
require("../databasepassword.php");
mysql_connect("localhost","myusername",$dbpassword);
Now your password is perfectly safe.