Jump to content

So, I'm new to PHP...


soundeffects

Recommended Posts

And I'd like to ask something?

 

Someone I know told me that they had made a PHP file to show different pictures at different times of the month. But as one file. If that makes sense. I'd like to make one too, would anybody know how to go about it/where to start?

I'm not asking for you to write it all out for me, just a little push/shove/kick in the right direction?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/77709-so-im-new-to-php/
Share on other sites

What you need is to put all your images up. In your page have an array of the names and a use a random number generator to pick the image name out. This can be used to display the picture you want. Not sure if you want a specific image for a specific day?

 

Desmond.

 

 

Link to comment
https://forums.phpfreaks.com/topic/77709-so-im-new-to-php/#findComment-393373
Share on other sites

Say if you wanted different pictures for different months, you would so something like this....  for more information have about the php data function (http://au3.php.net/date)

 

<?php

// Get the month as a digit 0-12
$month = date("n");

switch($month) // Choose which image to display for which month by using a switch more info can be found here(http://au3.php.net/manual/en/control-structures.switch.php)
{

case $month == 1:

echo '<img src="january.jpg" alt="" />';

break;

case $month == 2:

echo '<img src="february.jpg" alt="" />';

break;

// etc....
}

?>

 

Hopefully this helps!

Link to comment
https://forums.phpfreaks.com/topic/77709-so-im-new-to-php/#findComment-393376
Share on other sites

otuatail: Thanks for the reply. What I was thinking was to have an image up for about 28 days of the month and have a seperate image for the other two days. Once those days were over, I'm planning on having it revert back to the original image.

 

dual_alliance: Thanks, that's pretty close to what I want. Is there any way to tweak it so the pictures change on a certain date of the month?

Link to comment
https://forums.phpfreaks.com/topic/77709-so-im-new-to-php/#findComment-393383
Share on other sites

Yeah you could do something like....

 

<?php

// Get the month as a digit 1-12
$month = date("n");

// Get the day as a digit 1-31
$day = date("j");

switch($month) // Choose which image to display for which month by using a switch more info can be found here(http://au3.php.net/manual/en/control-structures.switch.php)
{

case $month == 1:

if($day == 23)
{
echo '<img src="specialImage.jpg" alt="" />';
}
else
{
echo '<img src="normalImage.jpg" alt="" />';
}

break;

case $month == 2:

if($day == 13)
{
echo '<img src="specialImage.jpg" alt="" />';
}
else
{
echo '<img src="normalImage.jpg" alt="" />';
}


break;

// etc....
}

?>

 

Probably a more productive way of doing it, but it should help you :)

Link to comment
https://forums.phpfreaks.com/topic/77709-so-im-new-to-php/#findComment-393385
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.