Jump to content

Anyone any idea on how


paul1981

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[quote author=ToonMariner link=topic=103462.msg411936#msg411936 date=1155064780]
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.
[/quote]

Lies! :-P
Link to comment
Share on other sites

Firstly thanks for you fast replys.

[code]<?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>";
}
?>[/code]
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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[code=php:0]
<?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>";
}
?>
[/code]

Should do it... It will look in /images/ no matter where its called from instead of current directory/images...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.