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
 
Hi there.
To achieve something like what you wanted is not hard.
Your table structures will be simple.
Simply have this:

id int(6)
pagename varchar(20)
title varchar(50)
content text
activestatus tinyint(1)

Then, in your index.php, you can have all the layout setup, and basically you just need to replace the content according to what you have in the database by doing the query according to the page that's passed in from query string.
if (index.php?page=home) is called, then you can call:
$sql = "SELECT content FROM mycontent WHERE pagename='$page' AND activestatus=1";

From the Admin Site, you could have an HTML text editor set up.
I would recommend you to use FCK Editor, which have very nice structures, and it supports browsing of Image from your own web server, unlike other Editor.
You can just load the content FROM the database, and store it in the editor.
Then, once you are done with it, you can just resave back to the database.
All the HTML will be formed for you, so you don't really need to worry about the content.

With this, you actually can generate your menu of the website as well.

To further complicate the system (if wanted), you can write another script to actually allow you to have sub-menus and sub-sub-menus. But this is a further stage in your development.

Hope this helps.
 
Thanks for the reply m8, it was helpful.

However im after a more complex system like you say. The admin side of things is no problem for me, i can write up some php scripts to edit and delete sections no problem. Im abit stuck with basiclly how to go about setting up the system. Tables etc which you have helped me with. However your method means i will have to create a section.php eg. home.php to add the mysql code to call from the database. I want one page that is an include in the index.php such as content.php. Then in the address bar a variable is included for content.php to call the specific database table row so the content is then displayed on the page. The links would need to be automaticlly populated in the site nav menu. So basiclly when a link is clicked the content.php calls the specific table row and the content is desplayed.When a new section is added through admin the nav bar menu is automaticlly updated with the content title link. When a section is deleted the site nav menu is updated also and the link is gone.

Thats basiclly what im trying to achieve.

If you could shed alittle more light for me i would be greatful, especially trying to get the nav menu to updated with a working link to call content after a new section has been added and table structures etc.

I need it to be driven compeltly by online php forms so everything can be done through admin when he / she logs in.

Thanks all

Jim
 
Technically you could do most of this with one single table.

(int)id (id number passed per section)
(int)type (used for sidebar, header, whatever)
(vchar)title (title for the page)
(blob)content (content to go under the body of the page)

Using this for a simple page you could just use this as a hyperlink
Code:
<a href="index.php?id=(section id)">(link info here)</a>
Then, on the recieving side you merely need to pull that section id and look it up in your table to retrieve what should be on the page.
 
That's what I mean.
You don't need to have home.php or page1.php.
You just need to call the page by the name.
Sample:

index.php?page=home

You will go to the db, select * from tblcontent WHERE pagename='$page' will be able to give you the content of tblcontent and you just spit out at index.php.

So, basically you just need two pages, one index.php, and one content.php to do the content management.
In the content.php, you will need to identify the pagename as you want to call it as well.

Hope this is clearer for you.
 
My website, WebRevolt Studios is driven from a database, but includes different pages into the main index.php page.

It works very similar to the replies above.

visit the link below to look

Regards,

Martin

Computing Help And Info:
 
ahhh,

kk i see how it works now. Yeh this could work very well.

However moving onto the problem of sub links to other sub sections and more sub sections etc on each of the sections created in the table. I know were getting complicated now but how would i go about doing this?

Basiclly im aiming to get the site fully manageable via the admin utility, i dnt want to have to create new pages of php anywhere, unless really needed.

When i enter information into the content window that will be uploaded into a row in the mysql table. How will allow pictures to be displayed? Can i just user HTML tags within the edit window? eg. <img src="dir"> and other tags such as <b>. Would this work?

Can anyone help with getting the sub sections sorted?

Thanks

Jim
 
Yup. with the editor that I recommend, you just need to browse and be included in the tag. Quite easy.

While for the sub sections are the same, you just need another table to store the relationship, and while you are on the index.php, you can call a loop through this table to generate the sub sections.

 
Ok guys,

Been doing loads of work on the content system side of the site. However ive come accross a slight problem, or shall we say set back.

Basiclly ive done what woodyroundup has said above. Ive got a table with the following structure:

id int(6)
pagename varchar(20)
title varchar(50)
content text
activestatus tinyint(1)

Ive coded up a content.php which calls from the specific pagename from the database when the pagename is specified in the URL. I originally included this content.php into the index.php and i could use the following url to call from the database:

index.php?page=home

This successfully called the specific row of the table that was then displayed as content on the site. I had to make changes to my index.php to accomadate this new feature as previously i had an actual php page for each section and i included these pages in the index with the same url: index.php?page=home

I previously used the following code to include these php pages in the index.php:

Code:
<?php
if (!$_GET["page"]) {
  $_GET["page"] = "home";
}
$content = $_GET["page"] . ".php";
if (!file_exists($content)) {
  $content = "404.php";
}
?>

and in the actual table cell where the pages would be included i had:

Code:
<?php include($content); ?>

However i deleted both these bits of code and replaced the original include function in the table cell of the index.php to include the content.php. I was then successfully able to call table rows from the database using index.php?page=home or index.php?page=test etc. What ever was in the table.

However this is when i remembered something important. I will still have SOME set php pages in my site. Such as the registration php page and the downloads php page. These pages are included in the index.php like they were originally. But i cant have it both ways with the database and the php pages both included in the index.php.

So i decided to use this URL:

index.php?page=content&pagename=home

This way i could still include php pages within the index.php and could also include rows from a mysql database. However ive been told that passing variables through the URL in the way i have done above isnt very efficient and can cause problems. And when i get to the stage in my site development where i start using sub sections in the database and relationships to other tables (which ill need help with btw lol) the URL could get very long and messy with lots of variables been passed through in the way ive done it above so that i can include both php pages and database rows in my index.php.

What im woundering, is that is there any other way to go about doing what im trying to do. I like the way the database system works where i can call content to the index.php through the content.php. However i cant do it both ways can i.

Forms like the register.php are very complex and cant be copied from a php file to a mysql row can they?

Basiclly people im looking for some advice on how i should go about it.

Thanks alot

Jim
 
No problem with that. See how long the eBay's and Yahoo's url is?
:)

You could also do this:

$passedurl["page"]="content";
$passedurl["pagename"]="home";
$theurl = base64_encode(serialize($passedurl));

To get back all value:

if (isset($_QUERYSTRING))
{
$url = unserialize(base64_decode($_QUERYSTRING));
echo $url["page"];
echo $url["pagename"];
}

With this, people won't be able to see what you are passing.
 
woah lol,

Thats mad m8. Very interesting though.
Ive decided to agree with you about the long URL thing. Theres nout wrong with that tbh.

The method you first gave me is working as a great base. Ive added a few more fields to the table, and ive got the nav menu working for each row in the table. Ill keep you informed. No doubt ill run into trouble soon lol.

Thanks m8

Jim
 
Hi guys,

Ok, ive got the system working exactly how i want it now. Everything works fine. Im pleased with the progress. However im now looking to move onto the next stage or the content system development for my site.

I want to be able to have sub sections. This would mean having new tables with relationships etc, which i dont know much about. Well i know about normalisation, primary keys and foreign keys and can construct a fully normalised database with relationships in access, jus not mysql.

Im guessing in order to have sub sections im going to need more tables and relationships.

Below is all the code im using at the minute for my current system:

The table "brisk_content" is structered like this:

Code:
CREATE TABLE `brisk_content` (
  `id` int(6) NOT NULL auto_increment,
  `pagename` varchar(20) NOT NULL default '',
  `linkname` varchar(20) NOT NULL default '',
  `title` varchar(50) NOT NULL default '',
  `content` text NOT NULL,
  `location` enum('nav','info') NOT NULL default 'nav',
  `membership` enum('yes','no') NOT NULL default 'no',
  `activestatus` tinyint(1) NOT NULL default '1',
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `content` (`content`)
) TYPE=MyISAM AUTO_INCREMENT=8 ;

My content.php has 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";

$sqlmem = "SELECT membership FROM $table WHERE pagename='$pagename'";
$rsltmem = mysql_query($sqlmem);
$fetch_membership = mysql_fetch_array($rsltmem);
$membership = $fetch_membership["membership"];

if($membership == "yes") {

require 'config/db_connect_login.php';
if ($logged_in == 0) {
	header('Location: index.php?page=errors/notlogin');
	die('');
}
$db_object->disconnect();
}
?>
<div align="center">
  
<table width="100%" align="center">
  <!--DWLayoutTable-->
  <tr> 
    <td width="100%" height="131" valign="top"><p><br>
      </p>
      <p align="center"> 
	  
<?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!");

$table = "brisk_content";

$checksql = "SELECT activestatus FROM $table WHERE pagename='$pagename'";
$checkrslt = mysql_query($checksql);
$actstatus = mysql_fetch_array($checkrslt);
$activestatus = $actstatus["activestatus"];

if($activestatus == "1") {

$sql = "SELECT * FROM $table WHERE pagename='$pagename' AND activestatus=1";
$rslt = mysql_query($sql);

while ($result = mysql_fetch_array($rslt))

	{     

     $output_content = wordwrap($result['content'], 50);
	 $output_title = wordwrap($result['title'], 20);

?>

<font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="4C4C4C">

<?php

	 echo "<table width='100%'>";
	 echo "<tr>";
	 
     echo '<td><pre><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif">' . $output_title .'</font></pre></td>

		   </tr>';
		   
	 echo "<tr>";
	 
     echo '<td><pre><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></pre></td>

		   </tr>';


	 echo "<tr>";
	 
     echo '<td><pre><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif">' . $output_content .'</font></pre></td>

		   </tr>';


	}
echo "</table>";

} else {

echo "<pre><font color='4C4C4C' size='1' face='Verdana, Arial, Helvetica, sans-serif'>This page has either been tempory disabled by admin or does not exist</font></pre>";

}
?>

</font>
      </p></td>
  </tr>
</table>

My site nav menu and info menu have to seperate php pages. My nav.php consists of the following code:

Code:
<div align="center">
  
<table width="140" align="center">
  <tr> 
    <td width="140" valign="top" align="center"> 
      <?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!");

$table = "brisk_content";

$sql = "SELECT * FROM $table";
$rslt = mysql_query($sql);

	 echo "<br>";
	 echo "<table width='140'>";
	 echo "<tr>";
	 echo '<td><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="index.php?page=home">Home</a></font></td>
		   </tr>';

while ($result = mysql_fetch_array($rslt))

	{
	
	 if($result['location'] == "nav") {
		
	 echo "<tr>";
	 echo '<td><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="index.php?page=content&pagename=' . $result['pagename'] . '">' . $result['linkname'] . '</a></font></td>
		   </tr>';
		   
	}
	 
	}
	
	 echo "</table>";
?>
      <div align="left"></div></td>
</tr>
</table>

My info.php consists of the following code:

Code:
<div align="center">
  
<table width="140" align="center">
  <tr> 
    <td width="140" valign="top" align="center"> 
      <?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!");

$table = "brisk_content";

$sql = "SELECT * FROM $table";
$rslt = mysql_query($sql);

echo "<br>";

while ($result = mysql_fetch_array($rslt))

	{
	
	 if($result['location'] == "info") {

	 echo "<table width='140'>";
	 echo "<tr>";
	 echo '<td><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="index.php?page=content&pagename=' . $result['pagename'] . '">' . $result['linkname'] . '</a></font></td>
		   </tr>';
	 
	}
	
	}
	
	 echo "</table>";
?>
      <div align="left"></div></td>
</tr>
</table>

How would i get sub sections for each of my main sections?

How would i go about doing it. I dont really want to change any of my current system as it works great. I dont mind altering table structures etc though.

Anyone got any ideas?

Thanks alot

Jim
 
I would add a field to the table for a reference and just change the SQL statements. Something like -1 for base and then fill in the ID into the field for subs.

Example:

Pictures
-My Pictures
-Friend's Pictures

Pictures, being the root menu, would have this field set to -1 and "My Pictures" and "Friend's Pictures" would be set to 0 or whatever number is the autonumber ID for "Pictures". To form the menu it would be as simple as a select statement for -1 and then later a select statement on each menu item's ID to retrieve any sub menu items.
 
not to sure what you mean m8.

Could you explain in abit more details for me please :S

Sorry lol.

Is there any other way i could do it?

Thanks

Jim
 
Top level menu query (under the system I said):
Code:
$sql = mysql_query("SELECT `id` FROM `brisk_content` WHERE `level`='-1'");

Then, using the ID numbers returned you would do a loop through the array and the query for doing that would look similar to this:
Code:
$sql = mysql_query("SELECT * FROM `brisk_content` WHERE `level`='$menu_id'");

The code to process the loop etc is up to you on your end, but, I hope this gave you more of an insight into what I was trying to point you towards.
 
ahhhh,

ok m8, i get ya now :)

Thanks for that, ill develop it further and give it ago :)

Jim
 
Ok,

Matt ive been reading your code above, and now fully understand exactly what you mean here. Yes it is a good way and will work.... however, it will only allow me to have 1 sub section. And i will be needed... well who knows. Could be 3, 4, 5 or 6 sub sections within my site.

I was trying to think howto slightly alter your code to allow for this. However im having trouble. Even if we could change it to allow several sub sections, the table could get messy.

Do you know how i can accomplish what im trying to do using your code?

Would it be possible to do using a few tables in a relationship? Or is it easier to do it Matts way if we could change the code. However in mysql i dont know anything about table relationships so i would need some getting started help.

This is what im imagining: A simple table cell on my content.php next to the actual display table which shows content. When a section is selected from the actual site nav bar the content.php displays the content for the section (already accomplished this) and the little table cell also on the content.php displays a list of sub sections for the main section thats been selected from the site nav menu. Then when one of the sub sections is selected from the little table cell on the content.php the content for that selected sub section is displayed along with a new list of sub sections for that selected sub section and so on.......

I know it sounds confusing but you will know what i mean.
Ive got this far so far: Test the above out and you will see what i mean.

If i could get the sub section system working how i imagine it above, it would be spot on, exactly what im trying to do. I know it could be done. I just need some help getting started.

Any help would be greatly appriciated.

Thanks alot

Jim
 
anyone got any ideas?

I know ive asked alot of questions about this, but im really not sure which way to go about doing it. If someone could give me a head start with how to go about it and i can do everything else myself.

Thanks again - all help is appriciated.

Jim
 
Jim, There's no limit on the number of sub sections using the system I mentioned (well, unless you run out of room in your database). You just need to keep going with the system of checking the next level down. The code to actually do this could be done in several different ways, but the database shouldn't need to change. That referral field in the database is the key as sub section 2 would have sub section 1 as it's referral and sub 3 would have sub 2 etc etc etc. It's mostly just a lot of query work done with loops and if statements. Sorry for not replying sooner but I was out for the weekend.
 
Hi m8,

No probs :)

But what i mean is...

In section 1 (main section) i will have -1 in the level (referal) field. Then in sub sections 2 i will i have section 1's ID. Then i would need to have -2 also in the level field for sub sections 2. I cant have both can i?

Or do you mean for sub sections 3 i would have sub section 2's ID?

Thing is though, in the query for the getting ID's, i have a set variable for the where statement as '-1'. This is the query:

Code:
$sql = mysql_query("SELECT `id` FROM `brisk_content` WHERE `level`='-1'");

How would i change this to find ID's for each sub section as i click through them on the page? Bearing in mind sub sections and main sections could be deleted. Its all abit mind boggling for me, but once i get going i can do it. Just need pointing in right direction if im honest.

Thanks alot

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top