1
hipoonios
Need help from a PHP expert
  • 2010/2/11 17:43

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Hello,

This a more a general PHP question than a XOOPS question. But maybe I can get help with this anyway. As I know there is some php experts hanging out here.

Well,

I currently have a logo for each day of the week.

The is the code I'm using in my theme:

<{php}>
$today=date(l);

if(
$today==Monday){
echo 
"<td background='www.mysite.com/logo1.png' border='0'>";
}

elseif(
$today==Tuesday){
echo 
"<td background='www.mysite.com/logo2.png' border='0'>";
}

elseif(
$today==Wednesday){
echo 
"<td background='www.mysite.com/logo3.png' border='0'>";
}

elseif(
$today==Thursday){
echo 
"<td background='www.mysite.com/logo4.png' border='0'>";
}

elseif(
$today==Friday){
echo 
"<td background='www.mysite.com/logo5.png border='0'>";
}

elseif(
$today==Saturday){
echo 
"<td background='www.mysite.com/logo6.png' border='0'>";
}

elseif(
$today==Sunday){
echo 
"<td background='www.mysite.com/logo7.png' border='0'>";
}
<{/
php}>


Now I want to take this one step further.

I want a normal drop-down menu there my users can select which logo they ALWAYS want. Their choise should be saved in a cookie. But if they don't select a logo, then the logo for the day should be displayed. It would also be great if there should be a default setting in drop-town to clear/delete the cookie.

Like this:

Resized Image

I would really appreciate if someone could help me with this.

Thanks.

2
ghia
Re: Need help from a PHP expert
  • 2010/2/11 20:08

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Try
<script type="text/javascript">

function 
setCookie(c_name,value,expiredays)
{
var 
exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name"=" +escape(value)+
((
expiredays==null) ? "" : ((expiredays==null) ? "" ";expires="+exdate.toGMTString())+
";path=/";}

function 
SetLogoSel()
{
  
document.formSelLogo.elements['SelLogo'].selectedIndex;
  if (
document.formSelLogo.elements['SelLogo'].options[x].value == 'default')
  {
    
setCookie('SelLogo','',-1);
  }
  else
  {
     
setCookie('SelLogo',document.formSelLogo.elements['SelLogo'].options[x].value ,100);
  }
  
window.location.reload()
}
</
script>

<
form name="formSelLogo">
<
select name="SelLogo" onchange="SetLogoSel()">
<
option value="default">Logo of the day</option>
<
option value="Monday">Monday</option>
...
<
option value="Sunday">Sunday</option>
</
select>
</
form>


Get the cookie value:
if (isset($_COOKIE["SelLogo"]))
{
  
$today=$_COOKIE["SelLogo"]; 
}
else
{
  
$today=date(l); 
}


edit: added some missing brackets and page refresh.
edit: use option value iso option text
edit: use root path cookie

3
Burning
Re: Need help from a PHP expert
  • 2010/2/11 20:17

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi'

Nice tip !

... but (I am ashamed to ask such question ), where we have to enter this code ?

Quote:

if isset($_COOKIE["SelLogo"])
{
$today=$_COOKIE["SelLogo"];
}
else
{
$today=date(l);
}

4
ghia
Re: Need help from a PHP expert
  • 2010/2/11 20:31

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
Nice tip !
If it prooves to work!
Quote:
I am ashamed to ask such question
Why? Such people stay dumb!
Quote:
where we have to enter this code?
In place of
$today=date(l);

5
hipoonios
Re: Need help from a PHP expert
  • 2010/2/11 21:24

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Thank you very much for helping me out Ghia. I really appreciate it.

Unfortunately the php code gives me a parse error. Can you please re-check the code.


edit: it would also be nice if the page will refresh after selection so the user will see the change instantly.

6
ghia
Re: Need help from a PHP expert
  • 2010/2/12 0:14

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Added some missing brackets and page refresh.

7
hipoonios
Re: Need help from a PHP expert
  • 2010/2/12 10:34

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


Thank You! Got it almost to work now.

It works but it's a bit buggy.

If you go to my site:

http://www.recordedamigagames.org and for example choose the monday logo. Now go to any page. Like the FAQ. Now it will change back to the logo of the day again.

Another bug. If you select "select logo" it doesn't show any logo at all. It would be great if it will show the default (logo of the day) if you pick that.

Is it possible to have other names for the choises in the dropmenu? It's seem to be not so simple. I tried to rename it like: <option value="Monday">Batman</option> But it wont load any logo.

8
bjuti
Re: Need help from a PHP expert
  • 2010/2/12 10:54

  • bjuti

  • Just can't stay away

  • Posts: 871

  • Since: 2009/1/7 2


Grat site. I was user Amiga computer more than 15 years :) Now i'm 30, so it's half of my life :)

9
ghia
Re: Need help from a PHP expert
  • 2010/2/12 10:58

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


The options[x].text has to be options[x].value

10
hipoonios
Re: Need help from a PHP expert
  • 2010/2/12 11:26

  • hipoonios

  • Friend of XOOPS

  • Posts: 298

  • Since: 2005/9/24


You solved two of my problems in less than five minutes!

Now there is only one bug left. The logo change if go to another (module) page.

If you ever get an idea how to solve this let me know :)

bjuti: Nice, You should install the Winuae Amiga emulator so you can enjoy these old classic games again

Login

Who's Online

254 user(s) are online (135 user(s) are browsing Support Forums)


Members: 0


Guests: 254


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits