Jump to content


Photo

Anyone any idea on how


  • Please log in to reply
11 replies to this topic

#1 paul1981

paul1981
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationleeds UK

Posted 08 August 2006 - 07:05 PM

Hi all
I have hit a wall and am looking for a new idea if anyone has one.

Here is what i am doing.
I have a function that displays a box witch the text sits in.
everything is fine with that and it works great.
how ever i find i keep having to create more and more of the same function but with differant paths for the images file.
images/image1.gif
../images/image..gif
and so on depending on were the page is i am linking from.

I just wondered if anyone has any ideas on a better way to manage the function.
so i could just have the 1 set of functions for every page no matter what folder they were in.

Any ideas welcome.
Paul1981
Paul Ainsworth

#2 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 08 August 2006 - 07:07 PM

Can you please post the code for the function, and try to explain the situation a little clearer. I would mainly suggest puttin the function in a class and include the class only in every page, but im not totally sure what your asking. Or you could set a variable in the function to take the path of the file you want it to look at.
http://thewebsolutionprovider.com - A Solution For Everything Web!

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 08 August 2006 - 07:13 PM

Use objects. And only change the paramaters/values. One function/class accross the board. (In other words, take an object oriented approach)
PHP Ninja

#4 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 08 August 2006 - 07:15 PM

Exactly!
http://thewebsolutionprovider.com - A Solution For Everything Web!

#5 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 August 2006 - 07:18 PM

you could define the absolute path instead.

so if the image was in www.ursite.com/global/images/image1.gif you could just define the path as:

"/global/images/image1.gif"
follow me on twitter @PHPsycho

#6 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 August 2006 - 07:19 PM

OOP is great but in many cases its a bit overkill...

Unless you have a massive site i see few reasons to use it - especially in this case when its only a file path that needs to be defined.
follow me on twitter @PHPsycho

#7 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 08 August 2006 - 07:23 PM

OOP is great but in many cases its a bit overkill...

Unless you have a massive site i see few reasons to use it - especially in this case when its only a file path that needs to be defined.


Lies! :-P
PHP Ninja

#8 paul1981

paul1981
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationleeds UK

Posted 08 August 2006 - 07:41 PM

Firstly thanks for you fast replys.

<?php
function opentable()
{
echo"<table width=\"600\"  border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  <tr>
<td width=\"15\"><img src=\"image/left_side.gif\" width=\"15\" height=\"22\"></td>
<td width=\"100%\" background=\"images/middle.gif\"></td>
<td width=\"15\"><img src=\"images/right_side.gif\" width=\"15\" height=\"22\"></td>
</tr>
<tr><td>";
}
?>
Right that the function for opening the table as i said in the last post it works fine.
I will try to explain in more detail this time.
Ok main folder is say index.php and also in that folder is the images folder.
you call the function on the index and it opens the table fine.
now i create a folder in side the main folder called say folder1 and have lets say another index.php in there. Now when i call the function its still looking at images/left_side.gif as the path to the file when in fact the path should be.
../images/left_side.gif
So to solve this i have 2 functions
opentable and opentable1
Its working find but i am finding that every time i add a new folder i need to add a new function
i was wondering as i said above if there is a better way to manage the function and just have 1 function for all.

What about an array? been playing and have it sort of working if i echo the correct number $image[2] say of 2 is ../images/left_side.gif. But never used arrays before so not that good with them.

Thanks again for any ideas
Paul1981

Paul Ainsworth

#9 paul1981

paul1981
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationleeds UK

Posted 08 August 2006 - 07:52 PM

Caesar could you explain a bit more about the below? Never heard of that.
Use objects. And only change the paramaters/values. One function/class accross the board. (In other words, take an object oriented approach)

Paul1981
Paul Ainsworth

#10 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 August 2006 - 08:14 PM

Ok Don't believe me....


follow me on twitter @PHPsycho

#11 paul1981

paul1981
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • Locationleeds UK

Posted 08 August 2006 - 08:30 PM

Sorry ToonMariner I do believe you mate. Just wondered what ideas the others had also.

Paul1981
Paul Ainsworth

#12 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 08:30 PM

<?php
function opentable()
{
echo"<table width=\"600\"  border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  <tr>
<td width=\"15\"><img src=\"/image/left_side.gif\" width=\"15\" height=\"22\"></td>
<td width=\"100%\" background=\"/images/middle.gif\"></td>
<td width=\"15\"><img src=\"/images/right_side.gif\" width=\"15\" height=\"22\"></td>
</tr>
<tr><td>";
}
?>

Should do it... It will look in /images/ no matter where its called from instead of current directory/images...
Why doesn't anyone ever say hi, hey, or whad up world?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users