Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Site Management System help

Status
Not open for further replies.

JamesCliff

Programmer
Feb 16, 2005
106
GB
Hi all,

Right ok, got big ideas but unforntunatly i lack in knowledge in order for me to carry some of them out :(

So im calling on your help. This could be a long thread but will be very helpful to others.

Basiclly.... Im creating a new site for myself ( and i want it to be competely managable through an admin who logs in and controls the site. Below is my idea.....

I have an index php which calls other pages into it that are in the navigation menu. For example home.php in the same dir as my index.php could be called using the following in the address bar:
index.php?page=home

However although each page (home.php and others) could be driven from a mysql database they would need to be created first and coded before been uploaded to the servers root directory and the index.php or other index include which houses the site menu links changing. I want to get rid of this. Basiclly im thinking if i could set up one page eg. content.php and a mysql table i could add new sections to the table. For example, i could log into my site as an admin and add a new section called Jokes. I would specify a name for the section (Jokes) and then click an add button. This would create a section called Jokes for my site. It would automaticlly add a link to the database table which would show up in my index site menu. When the link shows up in the index site menu it would be a link that when clicked, a specific section would be called from the mysql table or database through content.php. I could add or edit content in each section created by logging in as admin and then clicking the edit page and selecting an already created section from a combo box (drop down menu)and then clicking the edit button. This would show up a empty text box that i could add content to. Then i would save it. A section could be deleted in a simular way using a combo box.

By doing this method above everything could be done easily by the admin without having to create a new page. When a section is created by the admin a link is automaticlly added to the site navigation menu on the index.php. When the link is clicked the specific content would be displayed. Editing and deleting sections would be done through the use of combo boxes.

As far as i can see this method would work very well. Full, effective and efficient sections could be created with images, hyperlinks and text content. The user wouldnt be able to tell the difference whether they were reading a seperate php page for each section of just one page calling a mysql table unless they looked at the address bar. One problem would be creating sub sections from main sections that have been made. However i would cross this problem when we came to it.

Can anyone help me with this idea, it would be a great help and very apprriciated, even if i was given enough info to get started with eg. mysql table structures and page calling table help along with displaying a specific link in the site navigation menu along with other already created section links.

Or if anyone knows a better way to pull something like this off. Im open to all angles. Personally this is the only way i can see something like this been pulled off.

Thanks alot

Jim
 
Jim, you're starting to come around to the right path now. Yes, sub section 3 would have sub section 2's ids in their field. Also, I would think about turning the queries themselves into a function so that you need not retype the code per request. Lastly, You would change the query dynamically per previous query. Below is a small sample code to get you started. This is only a sample and will need to be altered to work in what you want it to do.
Code:
$sql = mysql_query("SELECT `id` FROM `brisk_content` WHERE `level`='-1'");
while (mysql_fetch_array($sql) = $sql_array) {
$level = $sql_array['id'];
$sql2 = mysql_query("SELECT `id` FROM `brisk_content` WHERE `level`='$level'");
}

This example shows you how to get the second level. To get subsequent levels requires you to build on this.
 
ive started work on the above code m8 :)

thanks alot.

Ive got it to this stage:

Code:
include("config/db.php");

$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");

$table = "brisk_content";

$sql0 = mysql_query("SELECT `id` FROM $table WHERE `level`='-1'");
while ($sql_array = mysql_fetch_array($sql0)) {
$level = $sql_array['id'];
$sql2 = mysql_query("SELECT `id` FROM $table WHERE `level`='$level'");
$chk_sql2 = mysql_query($sql2);
$chk_sql2_fetch = mysql_fetch_array($chk_sql2);
$level_id = $chk_sql2_fetch["id"];
$sql3 = mysql_query("SELECT * FROM $table WHERE `level`='$level_id'");
$chk_sql3 = mysql_query($sql3);
$chk_sql3_fetch = mysql_fetch_array($chk_sql3);
$chk_sql3_fetch["id"];

echo '<font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="index.php?page=content&pagename=' . $chk_sql3_fetch['pagename'] . '">' . $chk_sql3_fetch['linkname'] . '</a></font>';

}

Its not working as yet because im getting the following error message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/apache2/ on line 51

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/apache2/ on line 55

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/apache2/ on line 51

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/apache2/ on line 55

However even if it did work, wouldnt it show every sub section for every main section? Therefore to get it to show the sub sections for the specific main section that the user is currently on wouldnt it be easier to use the $pagename variable in the first query? For example:

Code:
$sql0 = mysql_query("SELECT `id` FROM $table WHERE `pagename`='$pagename'");
while ($sql_array = mysql_fetch_array($sql0)) {

It seems to me this could work. When a user clicks on a link in the site nav menu the page is opened using the following URL:


So the $pagename variable could work.

What do you think?

Also does the code i posted above make sense lol?

Thanks

Jim
 
Forgive me for being wrong (I normally am), buuut...

The Nav bar your'e talking about.

I want to ensure I know what's going on, because it might be of help to you and/or me.. :)

Way I'd try to do this would have 3 ID fields (None of this is precise code, more theory):
ID = Int, Autonumber (Key field)
ID_Parent = Int (Parent topic's ID)
ID_Order = Int (For ordering topics with the same parent)

ID numbers would not be consecutive per the example here, they would be auto-generated based on who the "parent" category is. Parent category is listed as well. (See below where I'm going with this)

From there, you'd select the current topic, it's parent, all subtopics of the parent, the parent's topic, all subtopics of the parent, and so on, and so on.. This would give you everything on the current level of the selected topic, with everything on every parent's level, but NOT unselected child-levels.


Main (ID=1, Par=0, Ord=1)
Sub1 (ID=2, Par=1, Ord=1)
Sub2 (ID=3, Par=1, Ord=2)
Sub3 (ID=5, Par=1, Ord=3)
Sub1 (ID=6, Par=5, Ord=1)
Sub2 (ID=7, Par=5, Ord=2)
Sub4 (ID=4, Par=1, Ord=4)
Sub1 (ID=8, Par=4, Ord=1)



Pseudo-Code:
Create array arMenu(Level, ID,Parent, Order, Name,Selected)
Create variables iPermSel, iTempSel

Store selected ID
iPermSel=6
iTempSel=6
<Concept Loop begins here>

Get Parent of iTempSel (ID 5)
iTempPar=Result (5)
Get children of iTempPar (Returns ID's 6,7)
arMenu(0,6,5,1,"Sub1",1) (iTempSel=ID so Selected=1)
arMenu(0,7,5,2,"Sub2",0)
iTempSel=iTempPar (5)
<Concept Loop ends here>

Get Parent of iTempSel(5) (Returns ID=1)
iTempPar=Result (1)
Get Children of iTempPar(1) (Returns ID's 2,3,4,5)
arMenu(1,2,1,1,"Sub1",0)
arMenu(1,3,1,2,"Sub2",0)
arMenu(1,4,1,4,"Sub4",0)
arMenu(1,5,1,3,"Sub3",1)
iTempSel=iTempPar (1)

Get Parent of iTempSel(1) (Returns ID=0)
iTempPar=Result (0)
Get Children of iTempPar(0) (Returns ID 1)
arMenu(2,1,0,1,"Main",1)
iTempSel=iTempPar (0)
iTempSel = 0, so stop the loop
iLoopSize=2

Then begin a loop, starting with the iLoopSize, counting down.
If the selected is set, drop down to the next level, order by the order field.

You should have the idea.


(Community thoughts on this idea, btw?)
 
Jim,
The error you're receiving means that you're trying to use mysql_fetch_array on an unset or empty variable. Also, your website tells me I don't have access to the restricted page so I didn't get a chance to review it. Lastly, you could easily use the current page as a marker as well, I just thought you were trying to do a flat index of links on the side like a menu.

Tkindree,
That's kinda the way I've been helping him to get this done (if I understand your psuedocode right), I just didn't have a field specified for order as that's more in the design.
 
I'm working on the same sort of thing, yes, there's a variety of them out there which i could "Borrow", but where's the fun in using someone else's code? Design your own and you learn from it so much better.

By starting on the current level and working back to root, you bypass all the other levels which haven't been "expanded" as of yet.

Additionally, as he's looking at having an admin area, the idea of an ordering field will assist in layout eventually. He could bypass the idea now, but if he's looking at design and code, down the road it might help substantially if the structure is in place.

Get away from code every once in a while, map out the flow of data (Don't have to Visio everything, just hand-written concept is normally enough), generally the answer comes from it. Too much "sit and stare at code" tells you where your code is wrong and what you're trying to accomplish, but not actually conceptualize the process.

Jim: You've got a good goal. Start with the goal, work backwards. You've got an idea, you understand how to do what you're looking for... Take a day, flow it out, should help dramatically. :)


(Throughout my life I've been called a spaghetti programmer, smart, but structurally evil. This helps. A lot.)
 
ok thanks alot m8 :)

I will do that and see how it goes :)

Matt, im trying to get only the sub sections displayed for each particular section. So when a link for a section/sub-section is clicked, then only the sub sections for that section are displayed. Therefore i could use the URL to help me with this :) Appriciate your help mate :) Im going to try and use your code, but change it to accomodate the current page as a marker. Im also going to give tkindree's code ago and see if i can understand it hehe :s

Im going to do more work on it tomorrow, fri and the weekend if i have chance. So do expect more posts from me hehe :)

Thanks alot

Jim
 
Thanks for all the help guys....

ive got a basic system sorted that does exactly what i want. I can have as many sub sections as i want for each sub section and so on.

See the results for yourself at You will need to sign up.

Tell me what you think of the code below.

I used the following code.

Code:
<?php

include("config/db.php");

$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");

if (!$_GET["pagename"]) {
  $_GET["pagename"] = "home";
}

$pagename = $_GET["pagename"];

$table = "brisk_content";

$mysql = "SELECT id FROM $table WHERE pagename='$pagename'";
$mysql_chk = mysql_query($mysql);
$mysqlfetch = mysql_fetch_array($mysql_chk);

$level = $mysqlfetch["id"];

$sql2 = "SELECT * FROM $table WHERE `level`='$level'";
$sql2_chk = mysql_query($sql2);
while ($sub_section = mysql_fetch_array($sql2_chk))

	{

echo '</font><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="index.php?page=content&pagename=' . $sub_section['pagename'] . '">' . $sub_section['linkname'] . '</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';

	}
	
?>

However at the minute i am entering values into the mysql table manually through phpmyadmin. However when it comes to developing the admin side of the site ill make some scripts that do this for me.

I might need help with these at a later date.

Thanks alot

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top