Thanks to the great replies Ive received here I have learned a couple of really good things that has improved my work tremendously and moved the work to revamp my site forward quite a bit.
I have a basic structure together now and content added that is not going to be all that dynamic such as pages like contact, about, etc. Now its time to move on to more dynamic content. I wont have a tremendous amount of content, but I am going to have some areas that may need updating, added to or deleted fairly frequently.
I dont know if know what I do will help but I'll give a brief bit of information. By day I work in telecommunications as a repair tech. In my spare time I do a lot of automotive service. Basic repairs, oil changes, troubleshooting, that sort of thing. I dont really rebuild transmissions and engines (though I have my own cars engine and tranny pulled and in the process of rebuilding them for some track duty use) but I do most other stuff. I carry a line of synthetic motor oils (and Im not trying to sell here, so if Im out of line, please let me know) and I offer a few other services. So obviously I want to list all this stuff on the site. So I will have the following pages on the site:
-An articles page. I like to write how to's for repairs and troubleshooting and would like to add those to the site
-A products page. Several categories and many products. I wont be selling on the site, just strictly product information.
-A services page. A basic run down of the services available and the cost and so forth.
-An Oil Analysis page. One of the services offered is the testing of motor oil. Basically the motor oil is tested and it gives you information on the health of the engine, motor oil, etc. I would like to list the results on the website, something like Manufacturer > Model > Engine > Test Results
What I had envisioned was using creating folders, for instance in the example of the articles, something like Alternator Replacement > Ford > Article.php. Then similar structures for the Oil analysis, products and services. Then using PHP to read those folders, create a link, then when that link is clicked on, the visitor taken to the next level, Ford in the example, then click on that link to be taken to the actual article.
I dont know if this is possible or not, it seems to me it would be as I have seen flat file database examples that do something similar. That all said (and I apologize for the long post, I just wanted to give as much detail as I could) I want to use this as a learning experience to learn a little about PHP. I dont want someone to do the work for me, but I dont want to be fed to the wolves either so to speak. So can anyone get me started, or point me to some existing examples that I can look at? Im open to other ways of doing this, but I didnt really want to use a MySQL database if I could avoid it.
At any rate, I'll stop there and see what the responses are and if there are any questions.
I would like to say thanks for all the help I have received thus far.
The next big question
Moderator: General Moderators
-
SyntheticShield
- Forum Newbie
- Posts: 18
- Joined: Tue Aug 19, 2008 2:46 pm
Re: The next big question
For what its worth, I found this code snippet:
But I wonder, would it be possible to make it pull up the content with the template if that makes any sense.
Code: Select all
<?php
$dir = ".";
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
echo "<a href=\"$file\">$file</a><BR>\n";
}
closedir($dh);
?>
Re: The next big question
I would say since you got this all down on paper already, your doing great. Next step would be to start making some pseudo-code. Write down in english what you want to accomplish on each page. Then figure out what kind of functions you will need for anything that will be repeated. A function to process directories, a function to process files, a function to display results maybe, etc... Then start turning your pseudo-code into actual code one piece at a time. When you run into trouble at least you know where to turn!
-
SyntheticShield
- Forum Newbie
- Posts: 18
- Joined: Tue Aug 19, 2008 2:46 pm
Re: The next big question
So I was surfing on the PHP website looking at the directory function and found an example there that seems to do a lot of what I am wanting:
Ive played a little with it, mainly commented out a couple of things I did not want displayed and will eventually delete the lines once I get everything sorted out.
I like this one over the other I posted because it does not show the "." and ".." links. However it does do a couple things I would like to figure out how to fix.
1. It maintains the underscores in the folder names. Which is to be expected, but is there a way to rename those in such a way that the underscore is removed? Can str_replace be used to do that? If so, can someone point me in the right direction?
2. It lists all the .php, .html, etc. files in the dirrectory and I would like to exclude those when just listing the folders. At some point, obviously, you would have to list the individual files, but I dont want files like idex.php listed. So how would I exclude those files?
Its also using tables which messes with my tableless template, but I'll tackle that after I get the other issues straightened out. Thanks again for everyone's help.
Code: Select all
<?php
// show directory content
function showDir($dir, $i, $maxDepth){
$i++;
if($checkDir = opendir($dir)){
$cDir = 0;
$cFile = 0;
// check all files in $dir, add to array listDir or listFile
while($file = readdir($checkDir)){
if($file != "." && $file != ".."){
if(is_dir($dir . "/" . $file)){
$listDir[$cDir] = $file;
$cDir++;
}
else{
$listFile[$cFile] = $file;
$cFile++;
}
}
}
// show directories
if(count($listDir) > 0){
sort($listDir);
for($j = 0; $j < count($listDir); $j++){
echo "
<tr>";
$spacer = "";
for($l = 0; $l < $i; $l++) $spacer .= " ";
// create link
$link = "<a href=\"" . $_SERVER["PHP_SELF"] . "?dir=" . $dir . "/" . $listDir[$j] . "\">$listDir[$j]</a>";
echo "<td>" . $spacer . $link . "</td>
</tr>";
// list all subdirectories up to maxDepth
if($i < $maxDepth) showDir($dir . "/" . $listDir[$j], $i, $maxDepth);
}
}
// show files
if(count($listFile) > 0){
sort($listFile);
for($k = 0; $k < count($listFile); $k++){
$spacer = "";
for($l = 0; $l < $i; $l++) $spacer .= " ";
echo "
<tr>
<td>" . $spacer . $listFile[$k] . "</td>
</tr>";
}
}
closedir($checkDir);
}
}
if($_GET["dir"] == "" || !is_dir($_GET["dir"])) $dir = getcwd();
else $dir = $_GET["dir"];
// replace backslashes, not necessary, but better to look at
$dir = str_replace("\\", "/", $dir);
// show parent path
$pDir = pathinfo($dir);
$parentDir = $pDir["dirname"];
// Below line provides link back to the start page for products
echo "<a href=\"" . $_SERVER["PHP_SELF"] . "\"><h3>Go Back</h3></a>";
// Commented below line out to remove directory path information
// echo "Current directory: " . $dir;
// Commented below line out to remove link back to parent directory
// echo "<a href=\"" . $_SERVER["PHP_SELF"] . "?dir=$parentDir\"><h4>Parent directory: $parentDir</h4></a>";
// Display directory content
echo"<table border=1 cellspacing=0 cellpadding=2>";
echo "<tr><th align=left>Product Categories</th>";
// specifies the maxDepth of included subdirectories
// set maxDepth to 0 if u want to display the current directory
$maxDepth = 0;
showDir($dir, -1, $maxDepth);
?>
I like this one over the other I posted because it does not show the "." and ".." links. However it does do a couple things I would like to figure out how to fix.
1. It maintains the underscores in the folder names. Which is to be expected, but is there a way to rename those in such a way that the underscore is removed? Can str_replace be used to do that? If so, can someone point me in the right direction?
2. It lists all the .php, .html, etc. files in the dirrectory and I would like to exclude those when just listing the folders. At some point, obviously, you would have to list the individual files, but I dont want files like idex.php listed. So how would I exclude those files?
Its also using tables which messes with my tableless template, but I'll tackle that after I get the other issues straightened out. Thanks again for everyone's help.