...

View Full Version : side bar/source file?



njfail
11-13-2010, 01:01 AM
Could someone help me make a source file that can be listed on a bunch of different pages?

I want to have a side bar with a list of picture links on a bunch of different pages.

But I don't want to have to add the list to each page manually, ya know?

Also, is there a way to have a button that switches the 'source file' to another source file?

What I want to do is, have a sidebar with a list of links that lead to different videos on my site. Almost all the pages will have the sidebar list on it. And I want a button at the top of the list that can change the list to a different list that I've compiled.

I've been told that this involves PHP? I'm only familiar with HTML and CSS though.

elitis
11-13-2010, 02:57 AM
You could try putting the links in a database table and then use php to select the links from the database

DrDOS
11-13-2010, 03:45 AM
To write a file to a page with PHP you use the include function. Just format the file exactly they way you want the code of the page to be, indenting and everything.
<?php include "movie_menu.txt"; ?>That file will be written verbatim to the page. Do not put php tags around the text or the PHP engine will try to execute it. You don't need to name it .php either. If you have multiple lists of movies it might be simpler to just make multiple pages and make the link above the list refer to another page with the include of another list. The reason for that is reusing the same page for another list involves making a server call which is another level of complexity. That will get you going and will work fine. After you've developed more PHP skills you can make a more automated version which will build the links from a simple listing and paginate them.

njfail
11-13-2010, 06:56 PM
I changed the html file to a .php extension, and created the pamlist.txt file in root directory/solo/

When I put in the code into the .php file where the list should appear;


<? php include "/solo/pamlist.txt"; ?>

This warning comes up on the page (no list :()


Warning: include(/solo/listpam.txt) [function.include]: failed to open stream: No such file or directory in /home/njfailc1/public_html/solo/index.php on line 64

Warning: include() [function.include]: Failed opening '/solo/listpam.txt' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/njfailc1/public_html/solo/index.php on line 64


:confused:

Its @ njfail.com/solo

poyzn
11-13-2010, 07:16 PM
When I put in the code into the .php file where the list should appear;

it appears exactly where you're putting include

check the file if it really exists and try this path


include $_SERVER['DOCUMENT_ROOT'] . '/solo/pamlist.txt';

DrDOS
11-13-2010, 07:22 PM
poyzn covered it, but simply omitting the first slash may have made it work, depending on the server settings, the slash in front usually refers to the root of the drive and not the root of the server.

njfail
11-13-2010, 07:41 PM
When I use:
(I've tried with and without the beginning '/')


<?php include $_SERVER['DOCUMENT_ROOT'] . '/solo/pamlist.txt'; ?>

This error occurs.



Warning: include(/home/njfailc1/public_html/solo/pamlist.txt) [function.include]: failed to open stream: No such file or directory in /home/njfailc1/public_html/solo/index.php on line 64

Warning: include() [function.include]: Failed opening '/home/njfailc1/public_html/solo/pamlist.txt' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/njfailc1/public_html/solo/index.php on line 64

But thats exactly where the file is...

poyzn
11-13-2010, 07:50 PM
check the file name, should be


include $_SERVER['DOCUMENT_ROOT'] . '/solo/listpam.txt';

njfail
11-13-2010, 07:51 PM
Browsing my server host's control panel, I found this in the php configuration menu... can any tell me what it means and how it could affect my php code?


Paths and Directories
include_path
Windows:
"\path1;\path2" c:\php\includes"
.:/usr/lib/php:/usr/local/lib/php

njfail
11-13-2010, 07:51 PM
check the file name, should be


include $_SERVER['DOCUMENT_ROOT'] . '/solo/listpam.txt';


When I do it without the <?php ?> tags it just says what you wrote in plain text..

poyzn
11-13-2010, 07:57 PM
Browsing my server host's control panel, I found this in the php configuration menu... can any tell me what it means and how it could affect my php code?

You can define custom include paths with set_include_path (http://php.net/manual/en/function.set-include-path.php) to specific directories on your site. That will allow you to include files from that directories without writing full path to the file

poyzn
11-13-2010, 07:58 PM
When I do it without the <?php ?> tags it just says what you wrote in plain text..

You should always wrap php-code with <?php ... ?>

njfail
11-13-2010, 08:01 PM
any other ideas of what the problem could be? I've checked the names several files, they're spelled correctly, all lowercase letters.

DrDOS
11-13-2010, 08:30 PM
You're on a Windows server so you may need to use backward slashes instead of forward ones ( most likely ), however you can just put the file in the includes folder and see if my original code, without any slashes works, or with includes\ . Makes it tough when your home server is Windows and the remote is Linux/BSD.

njfail
11-13-2010, 08:39 PM
You're on a Windows server so you may need to use backward slashes instead of forward ones ( most likely ), however you can just put the file in the includes folder and see if my original code, without any slashes works, or with includes\ . Makes it tough when your home server is Windows and the remote is Linux/BSD.

That returns this error:



Warning: include(\solo\listpam.txt) [function.include]: failed to open stream: No such file or directory in /home/njfailc1/public_html/solo/index.php on line 64

Warning: include(\solo\listpam.txt) [function.include]: failed to open stream: No such file or directory in /home/njfailc1/public_html/solo/index.php on line 64

Warning: include() [function.include]: Failed opening '\solo\listpam.txt' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/njfailc1/public_html/solo/index.php on line 64

Where is this file directory located at?? ".:/usr/lib/php:/usr/local/lib/php"

DrDOS
11-13-2010, 08:55 PM
Where is this file directory located at?? ".:/usr/lib/php:/usr/local/lib/php"That's not the one you should use, you either need it in includes or in the public_html folder. Can you tell us more about your OS and server type?

njfail
11-13-2010, 09:25 PM
Heres a snapshot of the php config file on my webhost's control panel:

What else should I look for to tell you guys?

I know justhost.com (my server host) users mysql.

njfail
11-13-2010, 10:06 PM
I've been learning through w3schools site, and they use a .php extension on their source file. (you guys told me to make it a .txt file :eek:)

So I've been trying several different things and I got it to work when I use the source file as a .php file along with the code


<?php include $_SERVER['DOCUMENT_ROOT'] . '/solo/pamlist.php'; ?>

Is that weird?
I've just started learning php, and if this ends up working, I'll probably change my footers/headers/menus to use php (its kinda tiring to go through each page changing the menu html code when I want to add/delete a menu option...)

DrDOS
11-13-2010, 10:48 PM
Well, there you are, I'm glad you got it solved. On my machine they can be plain .txt files and will be read directly verbatim to the page. Oh, the wonders of server settings.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum