|
|
Author |
Thread |
Wes
Paranoid (IV) Mad Scientist
From: Inside THE BOX Insane since: May 2000
|
posted 04-11-2003 01:55
*sigh* I know I'm going to regret opening this can of wrigglies, but someone promised me you guys would help when I decided to do so. *Glares at Skaarjj*
First, here's what I want to do: I'm adding a "related information" box to the bottom of my attraction articles and certain other pages on Texas Twisted. Preview of said box.
Inside the box would be a table of links to other pages and #targets on other pages (note that point) related to the current subject. For example, on the Big Tex attraction page, there would be the following links:
A box with similar links would appear on some of those pages, minus the link to the page you're on.
Additionally, each link might have either a "link type" icon or a thumbnail next to it. (A little speaker for the audio link, a thumbnail of Big Tex on others.) Not to begin with, but it's something to keep in mind. I have a habit of tweaking such things for months to come, so the solution has to be flexible.
Now, hard-coding such boxes on all those pages would obviously be redundant and a pain in the ass to maintain. So, I'm guessing PHP would be the way to go.
I would want to be able to create categories the same way one does in Movable Type, with the ability to assign multiple categories to certain pages. For example, a page about Big Tex would fall under both "Big Tex" and "The State Fair of Texas." A page specifically on The State Fair of Texas, however, would fall under "The State Fair of Texas," but may not fall under "Big Tex."
Would it be easier for me to convert the rest of the site to PHP, then do what I'm talking about, or is it easy enough to add this function alone to existing SHTML pages? (I'm really not sure what I would gain by converting the rest of the site right now.)
Also, how would I create the data that holds the categories and related pages? A list of URLs with related category names repeated with each one? A list of category names with page IDs of some kind? This concept is entirely abstract to me. I assume MySQL is the way to go, but I don't even know how to interface with it. (I see an "add new database" page in my DreamHost control panel, but that's all I know.)
I'm so completely lost on this and have two major concerns even attempting it: One, I want to make sure I set up the backend right from the very beginning so I don't end up getting near the end and realizing things aren't listing they way I want, then having to start over. Two, I want to be sure I set things up so I can easily expand the dynamic functionality to everything else in the future. (BTW, number three would have to do with dealing with my already existing Movable Type-based headlines and their categories.)
Ugh...I'm drowning already.
[This message has been edited by Wes (edited 04-11-2003).]
|
DL-44
Maniac (V) Inmate
From: under the bed Insane since: Feb 2000
|
posted 04-11-2003 03:14
Weeee =)
Well, just a couple things off the bat here -
1) Yes, PHP is perfect for this sort of thing
2) Yes, if you have a MySQL database available, you'll want to use it for this.
3) Start with these tutorials over at the GN for a basic intro to both PHP and MySQL -
http://www.gurusnetwork.com/tutorials/php/phptemplate/phptemplate.html
http://www.gurusnetwork.com/tutorials/php/phptemplate2/phptemplate2.html
And, hmm...the other one seems to be missing at the moment, but look in the coding section for DmS' 'dynamic php and mysql' tutorial
4) no, you don't need to convert the whole site. You will, however, need to check if the .shtml is configured to parse PHP, or you'll have to change the extension to .php.
So, just a quick note - plenty more info available, and plenty of directions to go in. I'll leave to Emp, or TP to give more solid advice on which direction would work best for you for now
|
Skaarjj
Maniac (V) Mad Scientist
From: :morF Insane since: May 2000
|
posted 04-11-2003 03:29
Hey...don't glare at me Wes...I fully intend to help out in every way I can...I repay my debts.
Now, you could store the categories and which apges are in each category in a database easily. You have a table for each category then with in that you have fields for page location and name. When someone looks through a category's page, what they will basically be seeing is that table parsed into a set of links (if you want a little preview image next to each article you could easily stick that into the table too). You could pull it all out on the one page using GET variables to dynamically build the page (so you'd have twistedview.php?cat=bigtex, then within the page you call that variable with $table_call = $_GET["cat"];
So that each page displays the categories it belongs to (and only those categories) you write a function in a functions page (which will become both your best friend and your mortal enemy by the end of this) and use as it's one argument a variable containing the title of your page. What that function will do then is call an array of all of your categories and cycle through them performing a MySQL query of "SELECT * FROM $curr_cat WHERE title = $title"; If that returns no rows...instead of using the die(); function I'd normally use to halt page processing and spit out an error message you could call the results of that query and check if(empty($result){ break; }else{store as variable category}
Now...you could also have another table that stores all your category names, call all the data out of that and use mysql_fetch_object as a while statement (so like
code:
while($cat_obj = mysql_fetch_object($result)
{
echo cat_obj->cat_name;
}
or you could do it as a for loop using mysql_result and using an incrementer so it only goes as long as the incrementer is less than or equal to mysql_num_rows...I'm not sure. I'm just thinking out loud right now....I'll get my thoughts back together and let you know if you contact me offline...I'm on the Q at 68471487 or MSN at skaarjj@hotmail.com.
|
Petskull
Maniac (V) Mad Scientist
From: 127 Halcyon Road, Marenia, Atlantis Insane since: Aug 2000
|
posted 04-11-2003 05:02
I don't see why you don't just <!--include a perl cgi with something like:
linkarray[1] = "http://www.ILikeThisPage.com"
linkarray[2] = "http://www.ILikeThisOneToo.com"
Loop until no more links in array
is linkarray[1] the calling page?
yes: do nothing
no: print linkarray[1]
end loop
Then you could just keep adding lines..
you could even (making it a little more complicated) keep all the links in a separate file and dumb them into the array (Why? So you don't need to keep writing the 'listarray[x]' part)
Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342
|
DL-44
Maniac (V) Inmate
From: under the bed Insane since: Feb 2000
|
posted 04-11-2003 05:09
petskull - but that wouldn't allow for the variation and flexibility of category.
skaarjj - I think you may be both jumping the gun, and over complicating things. Before getting too specific, he should definately get comfortable with the basics.
|
bitdamaged
Maniac (V) Mad Scientist
From: 100101010011 <-- right about here Insane since: Mar 2000
|
posted 04-11-2003 06:21
I'd start with just a little something included in the page. I'm pretty sure you can include php's the same as a virtual include.
Usually with things like this I put 10 times the work into actually setting up an admin screen for something like this, assembling data and displaying it is really the easy part.
The basic setup usually would be setting up a couple of database tables. One for the page information, one with the catagory information and one relational table connecting the two. This could also be easily done with flat files at first too (same sort of setup).
First step, consider your data, what you want to store (and what you may want to store, don't paint yourself into a corner). And how you are going to store it.
.:[ Never resist a perfect moment ]:.
|
Wes
Paranoid (IV) Mad Scientist
From: Inside THE BOX Insane since: May 2000
|
posted 04-12-2003 23:29
Hoo, watch those wormies squirm!
Okay, so I'll try those tutorials when I get home from work. In the meantime, I'm poking around the MySQL area in my DreamHost control panel. Looks like they offer php MyAdmin to handle databases. Good -- a Web interface. But, man, just looking at their demo, I'm already confused.
It looks like you can create many tables under one database. Okay.
Should I create one database for everything I plan to do with Texas Twisted in the future with different tables for different stuff? Or should I create one database solely for this "related info" function? It looks like I have to create a different host name (subdomain) and a unique user for each database, which would appear to make a collection of separate databases tedious to interface with.
Ugh...I've started half a dozen questions and deleted each of them after realizing I wasn't even sure what I was asking...
Maybe I'll go create a test database and table to just to get a little oriented...
|
Emperor
Maniac (V) Mad Scientist with Finglongers
From: Cell 53, East Wing Insane since: Jul 2001
|
posted 04-13-2003 06:18
|
Skaarjj
Maniac (V) Mad Scientist
From: :morF Insane since: May 2000
|
posted 04-13-2003 06:19
Go emps...this database planning guru....
|
Wes
Paranoid (IV) Mad Scientist
From: Inside THE BOX Insane since: May 2000
|
posted 04-13-2003 21:33
|
DL-44
Maniac (V) Inmate
From: under the bed Insane since: Feb 2000
|
posted 04-14-2003 00:01
Well, the biggest reason for the seperate table is to allow for an item to belong to multiple categories.
If you are *certain* that you won't need something to belong in more than one category, then go ahead and just add a field. If you want the added flexibility though, use a seperate table.
As far as updating two tables is concerned, it is quite simple when you make yourself an admin page with forms. phpMyAdmin is a great tool, but for routine addition of data, you'll want to make a custom form that can update two tables at once
some examples -
For my image gallery, I have 4 tables.
1 table for the gallery sections.
1 table for the images
1 table for the comments
and one table for the category relationships.
this enables me to have any category be a child of any other category (the 1st category is 'main' and all top level galleries belong to that category in the relational table). Each image belongs to one category, but that category can be a subsection of multiple categories.
Now, all of my ID fields are integers that auto increment, which tends to simplify matters more than a name does.
When updating, I use a page with forms. If I am adding a category, there are the form fileds to enter the info, and then there is a drop down menu that is populated on page load with the possible categories that this new category will be a sub-category of. If it is a top level gallery, I choose "main".
Therefore you don't have to remember ID #'s, the code does it all for you - shows *you* the category name, sends the DB the category ID.
Hope that helped a little rather than confusing a little
|
Emperor
Maniac (V) Mad Scientist with Finglongers
From: Cell 53, East Wing Insane since: Jul 2001
|
posted 04-14-2003 01:04
Wes: I interpetted this:
quote: I would want to be able to create categories the same way one does in Movable Type, with the ability to assign multiple categories to certain pages.
to mean that a page might have more than one category and if that is the case the above structure will work well if not then, as DL says, you only need a column in your page_table.
I would also recommend you use an autoincrementing number for the IDs as this will make things simpler.
As DL says you soon struggle with updating this by hand through phpMyAdmin which is why bd said a lot of your work will be on the admin. A good admin will make all the adding to different tables much easier.
Anyway its coming along nicely.
___________________
Emps
FAQs: Emperor
|
Wes
Paranoid (IV) Mad Scientist
From: Inside THE BOX Insane since: May 2000
|
posted 04-14-2003 01:43
Hokay, I get it.
I've been rethinking the issue of a page belonging to multiple categories, but I'm not really sure about it now, so I guess it's best to leave the option open with the link table.
So, that leaves us with constructing that admin dealie. Honestly, I've got no clue how to start that. No skills here.
So, what's the next step? (One step forward seems like two steps back, so far, so we've got to keep movin...)
[This message has been edited by Wes (edited 04-14-2003).]
|
Emperor
Maniac (V) Mad Scientist with Finglongers
From: Cell 53, East Wing Insane since: Jul 2001
|
posted 04-14-2003 04:38
Wes: OK the admin. The simplest thing would be to have a page for this:
my_related_admin.php
and set up a series of actions accessible through the URL like:
my_related_admin.php?action=add_page
my_related_admin.php?action=edit_page
as is required then set up the page thusly:
code:
if ($action == 'add_page') {
if ($HTTP_POST_VARS) {
//process stuff
}
//forms to add input
}
elseif ($action == 'edit_page') {
if ($HTTP_POST_VARS) {
//process stuff
}
//forms to add input
}
else {
//link to the various admin pages
}
Have a look at kuckus' contact page tutorial on how this kind of structure works as the principle is the same.
[edit: Its here:
www.gurusnetwork.com/tutorials/php/contact_page/contactpage_1_en.html
and describes how that kind of thing works]
___________________
Emps
FAQs: Emperor
|
Skaarjj
Maniac (V) Mad Scientist
From: :morF Insane since: May 2000
|
posted 04-14-2003 06:43
For my latest project I had to build an admin page exactly like this...here's my code
code:
<?
include $_SERVER["DOCUMENT_ROOT"]."/AVAccess/includes/functions1.php";
database_connect();
session_start();
if (!session_is_registered("SESSION"))
{
header("Location: ".$_SERVER["DOCUMENT_ROOT"]."/AVAccess/");
die("Your User account could not be verified, the session could not be continued");
}else{
echo "<font face=Verdana size=2>";
echo "<h1>Welcome to the Admin Module</h1><BR><BR><BR>";
echo "Please select from the following options:<BR><BR>";
echo "<a href=\"$PHP_SELF?tool=add_tchr\">Add Teacher</a><BR>";
echo "<a href=\"$PHP_SELF?tool=rmv_tchr\">Remove Teacher</a><BR>";
echo "<a href=\"$PHP_SELF?tool=add_hi_lvl\">Add High-Level User</a><BR>";
echo "<a href=\"$PHP_SELF?tool=rmv_hi_lvl\">Remove High-Level User</a><BR>";
echo "<a href=\"$PHP_SELF?tool=add_admin\">Add Admin-Level User</a><BR>";
echo "<a href=\"$PHP_SELF?tool=rmv_admin\">Remove Admin-Level User</a><BR><BR>";
echo "<a href=\"$PHP_SELF?tool=cncl_book\">Cancel booking</a><BR>";
echo "<a href=\"$PHP_SELF?tool=add_equip\">Add new Equipment item</a><BR>";
echo "<a href=\"$PHP_SELF?tool=rmv_equip\">Remove Equipment item</a><BR>";
echo "<a href=\"$PHP_SELF?tool=start_school\">Start of School Year Settings</a><BR><BR><BR><BR><BR><BR>";
$tool = $_GET["tool"];
if($tool == "add_tchr")
{
echo "Use this form to add teachers to the database<BR><BR>";
echo "<FORM action=\"admin_action_at.php\" method=POST><CENTRE>";
echo "<B>Name:</B> <input type=text name=\"tchr_name\"><BR>";
echo "<B>Code:</B> <input type=text size=3 name=\"tchr_code\"><BR>";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "rmv_tchr")
{
echo "Use this form to remove teachers from the database<BR><BR>";
echo "<FORM action=\"admin_action_rt.php\" method=POST><CENTRE>";
echo "<B>Name:</B> <input type=text name=\"tchr_name\"><BR>";
echo "<B>Code:</B> <input type=text size=3 name=\"tchr_code\"><BR>";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "add_hi_lvl")
{
echo "Use this form to add Higher Level Users (Librarians) to the database<BR><BR>";
echo "<FORM action=\"admin_action_ahl.php\" method=POST><CENTRE>";
echo "<B>Username:</B> <input type=text name=\"username\"><BR>";
echo "<B>Password:</B> <input type=text size=25 name=\"password\"><BR>";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "rmv_hi_lvl")
{
echo "Use this form to Remove Higher Level Users (Librarians) from the database<BR><BR>";
echo "<FORM action=\"admin_action_rhl.php\" method=POST><CENTRE>";
echo "<B>Username:</B> <input type=text name=\"username\"><BR>";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "add_admin")
{
echo "Use this form to add Admin Users to the database<BR><BR>";
echo "<FORM action=\"admin_action_aa.php\" method=POST><CENTRE>";
echo "<B>Username:</B> <input type=text name=\"username\"><BR>";
echo "<B>Password:</B> <input type=text size=25 name=\"password\">";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "rmv_admin")
{
echo "Use this form to remove Admin Users from the database<BR><BR>";
echo "<FORM action=\"admin_action_ra.php\" method=POST><CENTRE>";
echo "<B>Username:</B> <input type=text name=\"username\"><BR>";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "cncl_book")
{
echo "Use this form to cancel a booking<BR><BR>";
echo "<FORM action=\"admin_action_cb.php\" method=POST><CENTRE>";
echo "<B>Day:</B> <input type=text name=\"day\"><BR>";
echo "<B>Date:</B> <input type=text size=12 name=\"date\"><BR>";
echo "<B>Period:</B> <input type=text size=1 name=\"period\"><BR>";
equip_names();
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "add_equip")
{
echo "Use this form to add equipment to the database<BR><BR>";
echo "<FORM action=\"admin_action_ae.php\" method=POST><CENTRE>";
echo "<B>Name:</B> <input type=text name=\"equip_name\"><BR>";
echo "<B>Model No.:</B> <input type=text size=30 name=\"model_no\"><BR>";
echo "<B>Serial No.:</B> <input type=text size=30 name=\"serial_no\"><BR>";
echo "<B>Instruction Page:</B> <input type=text size=15 name=\"inst_page\"><BR>";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "rmv_equip")
{
echo "Use this form to remove equipment from the database<BR><BR>";
echo "<FORM action=\"admin_action_re.php\" method=POST><CENTRE>";
echo "<B>Name:</B> <input type=text name=\"equip_name\"><BR>";
echo "<B>ID Number:</B> <input type=text size=3 name=\"id\"><BR>";
echo "<input type=submit name=\"submit\" value=\"Submit\"></CENTRE>";
echo "</FORM>";
}
elseif($tool == "start_school")
{
echo "<B>WARNING: Only perform these actions before the start of the school year. They erase all the data in the booking tables when activated.</B>";
echo "Please Select the date of the first day of school:<BR><BR>";
echo "<form action=\"admin_action_ss.php\" method=POST>";
date_selector($prefix="school_start");
echo "<BR>Also, listed below are the starting times for each of the periods. If there are any discrepancies, please correct them:<BR>";
period_list();
echo "<input type=submit name=\"submit\" value=\"Submit\">";
echo "</form>";
}else{
echo "Please select one of the options above to proceed";
}
}
echo "<BR><BR><font size=1>";
echo "<a href=\"logout.php\">Logout</a>";
?>
|
Wes
Paranoid (IV) Mad Scientist
From: Inside THE BOX Insane since: May 2000
|
posted 04-18-2003 15:40
Sorry, guys, just a note to let you know the real world has gotten nutty (example: my car is dead again) and I'll be returning to this intermittently when I can.
|