Jump to content


Complete Database Driven Website


6 replies to this topic

#1 Woolf

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 23 July 2005 - 12:30 AM

Hello Everyone!

Just a quick introduction here... I'm Woolf and I'm starting up a new game resource website. So far I have created PotD, Featured Item, News, and Poll scripts. Everything is going smoothly, except for one thing...

How can I make the entire site database driven so you can add/delete/edit document pages right from the web? Does anyone have any suggestions on how this can be accomplished with PHP and MySQL? Another feature I would like is the ability to have the urls like http://www.mydomain.com/info/Title rather than something like http://www.mydomain....=info&mod=title or whatever.

If anyone can help me, I would greatly appreciate it.

Thank You Very Much :ph34r:

#2 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 23 July 2005 - 01:04 AM

Well here is and easy way for the ?page=2 or ?page=2&id=3

<?php
if(!$page)
{
echo 'If nothing is typed in it shows this';
}
if($p == 2 && $id == 1)
{
echo 'page 2 and id of one';
}
if($p == 2 && $id == 2)
{
echo 'page 2 and id of two';
}
if($p == 2)
{
echo 'page 2';
}
if($p == 3 && id =1)
{
echo 'page 3 & id =3';
}
if($p == 3)
{
echo 'page 3';
}
?>

Note: you can change the variable names.

Hope that helps you out with that part.

dEcade

Edited by dEcade, 23 July 2005 - 01:06 AM.


#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 July 2005 - 11:25 AM

Actually, that's the hard part, the easier way would be to use a switch().
But what he wants is mod_rewrite, not that. Read this: http://www.webmasterstop.com/125.html

If you want to add/edit/delete file's directly from your site, i would recommend going php.net and searching for "fopen" and "unlink" Those functions should get you started.

#4 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 23 July 2005 - 04:29 PM

To get the funnky URL trick you want, it is done with mod_rewrite. Search the P2L site for some tutorials on it. I wrote one myself as well, but it hasnīt been accepted yet, though if it was Iīd recommend it :)

#5 Woolf

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 24 July 2005 - 12:32 AM

Okay, so I understand the mod_rewrite part now... thanks rc69 :P . However, I'm still faced with the problem... how can I make it so that you can have pages like index.php?id=blah&id=blah, but make it so it's done through a database?

Here's basically my plan or 'structure' if you will:

The entire, or almost entire, website will be run off of a database, in which can be editable by an Online Publishing System that I'm currently making. The ability to add, delete, and edit pages on the website is a must. I don't know how this can be accomplished, however, I know it is possible. What needs done is a way to 'get' information from a database and then have it setup so I can link to the 'content' page. I'm sure this is probably quite simple, however, I have yet to find an answer.

If you're thinking of the switch() and stuff, that probably wouldn't work because remember, this is a Database Driven Website, meaning that you cannot edit the page files directly.

Whether the page url is /blah/blah/ or /index.php?id=blah&id=blah, I don't care, I'll just setup mod_rewrite to make it www.mysite.com/info/blah or whatever.

If anybody has any tips or suggestions on how I can accomplish this, I would be greatful for your contributions.

Thank You,

Woolf

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 24 July 2005 - 12:00 PM

First off, we need to know if you know anything about mySQL. Since i'm guessing you don't, you'll need to find a program on your server called phpmyadmin, open it up, and create a new table with 2 fields:
Field 1:
name - url
type - varchar
Default for the rest should be good.

Field 2:
name - file
type - text
Default for the rest should still be good.

We can get into more details once we get this sorted out, but till then, if you get confused, remember that this site has hundreds of tutorials on mySQL (mainly in the php section), use the tutorial search before asking more questions :P

#7 Woolf

    Young Padawan

  • Members
  • Pip
  • 12 posts

Posted 25 July 2005 - 12:37 PM

Thank You so much, everyone! 'Wybe' and 'rc69', the links to the tutorials you gave me helped me learn how to use these wonderful features. What I ended up doing is using the command "$id = $_GET['id']; if (!isset($id))" and then displaying the database on the page. I changed the database id variable to be 'test', rather than a number, and in the end, index.php?id=Test worked. I then used mod_rewrite to rewrite the url to http://www.mydomain.com/info/Test. It works great!

Thanks again everyone!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users