IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Need Help On A Simple Function
elexion
post Nov 6 2009, 10:48 AM
Post #1


Newbie
*

Group: Members
Posts: 20
Joined: 10-January 09
From: the netherlands
Member No.: 27,851



hey guys, It's been a while since i;ve been working with PHP but now i'm trying to write a simple
function for a website. I have included the function.php file into the index page so no problems there.
It just wont show if the function is actually working or not.
this is my code i hope someone can help me out or send me off in the right direction:
<?php
function date_switcher($date_switcher)
{
$switch = date("Y/m");
if ($switch==("2009/11"))
{
echo("succes");
include("style_succes.css");
?>
<link rel="stylesheet" href="style_standard.css" type="text/css">
<?php
}
else
{
include("style_standard.css");
}
}
?>
as you see i'm trying to make the function look at the date that's on the computer and based on that
to pick a stylesheet.
thanks for the help in advance i appreciate it.
Go to the top of the page
 
+Quote Post
justsomeguy
post Nov 6 2009, 03:50 PM
Post #2


The Old Man From Scene 24
*******

Group: Moderator
Posts: 14,826
Joined: 17-April 06
From: Phoenix
Member No.: 4,190
Languages: Focusing on PHP and JavaScript



Why can't you tell if it's working? You should be able to look at the HTML source and see what it included.
Go to the top of the page
 
+Quote Post
Redroest
post Nov 7 2009, 02:00 AM
Post #3


Newbie
*

Group: Members
Posts: 48
Joined: 23-October 09
Member No.: 34,709



To make things easier for all of us:

-please put the scripts between code tags
-Give an example on how you call the function
-Use texthints

I can't really tell what is wrong but, it would be easier if you format the script with tabs etc. This will allow you to scan your script much faster and when an error occurs it can also be spotted much faster:

Below is the formatted code. As you see its better to scan and it will save time on bigger scripts
CODE
<?php
function date_switcher($date_switcher)
{
  $switch = date("Y/m");
  //If the date is 2009 month 11
  if ($switch==("2009/11"))
  {
    echo("succes");
    include("style_succes.css");
    //I made php to echo the stylesheet code because it is easier to read without those ?> <?php tags. It now looks like it belongs within the if-statement
    echo "<link rel='stylesheet" href='style_standard.css' type='text/css'>";
  }
  else
  {
    include("style_standard.css");
  }
}
?>

Go to the top of the page
 
+Quote Post
ReQuNiX
post Nov 7 2009, 06:48 AM
Post #4


Newbie
*

Group: Members
Posts: 8
Joined: 9-September 09
From: Indonesia
Member No.: 33,692
Languages: (X)HTML, CSS, JS, PHP, SQL



QUOTE (Redroest @ Nov 7 2009, 10:00 AM) *
CODE
    echo "<link rel='stylesheet" href='style_standard.css' type='text/css'>";


Ah, a fatal quotation error...
It should be like this:
CODE
    echo "<link rel='stylesheet' href='style_standard.css' type='text/css'>";


(IMG:style_emoticons/default/smile.gif)
Go to the top of the page
 
+Quote Post
Redroest
post Nov 7 2009, 10:57 AM
Post #5


Newbie
*

Group: Members
Posts: 48
Joined: 23-October 09
Member No.: 34,709



Whaha (IMG:style_emoticons/default/biggrin.gif)
Go to the top of the page
 
+Quote Post
Ingolme
post Nov 7 2009, 01:27 PM
Post #6


Duotone Fox
*****

Group: Members
Posts: 3,584
Joined: 6-November 07
Member No.: 18,212
Languages: (X)HTML, CSS, Javascript, PHP, SQL, XML [DOM].



Are you making use of the $date_switcher parameter at all?
CODE
function date_switcher($date_switcher)

You might as well omit it if it's not being used anywhere.
Go to the top of the page
 
+Quote Post
elexion
post Nov 9 2009, 08:06 AM
Post #7


Newbie
*

Group: Members
Posts: 20
Joined: 10-January 09
From: the netherlands
Member No.: 27,851



QUOTE
Why can't you tell if it's working? You should be able to look at the HTML source and see what it included.


Well the testing page doesnt have a background color but the two different style sheets i'm trying to include do, And yes you're
right and i did check that after reading your tip and noticed the function.php file is indeed included in the page however still not working but thanks for pointing that one out

QUOTE
To make things easier for all of us:

-please put the scripts between code tags
-Give an example on how you call the function
-Use texthints

I can't really tell what is wrong but, it would be easier if you format the script with tabs etc. This will allow you to scan your script much faster and when an error occurs it can also be spotted much faster:


Sorry about the lack of texthints i figured the code being so small it wouldnt be a big problem figuring out. As for calling the function like i said i'm just picking up PHP again and therefor the test page only has the function included into it.

QUOTE
Whaha


heh glad i made someone laugh atleast (IMG:style_emoticons/default/wink.gif)

Thanks for the reply's everyone
Go to the top of the page
 
+Quote Post
elexion
post Nov 9 2009, 11:28 AM
Post #8


Newbie
*

Group: Members
Posts: 20
Joined: 10-January 09
From: the netherlands
Member No.: 27,851



alright i just managed to fix it (IMG:style_emoticons/default/smile.gif) thanks for the help everyone
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 23rd November 2009 - 01:15 AM