Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Creating a Database-Driven web page system
Old 07-12-2009, 12:24 AM Creating a Database-Driven web page system
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
This is something I've been curious about for awhile, and never got it to work quite right. Now I can admit that I'm not the greatest programmer in the world (I'm a Content guy!), but I do know the basics of PHP, and have created a few websites using the scripting language before.

Now here's the thing, I LOVE database design (and yet I HATE SQL). So along with already having the templates and design completed, I already have the MySQL database created and filled with the information I want to display on the website. Let me explain what I had in mind in setting this up:

I have a "Page" Table, in addition to other tables (not necessary for this part of the CMS though), and the following columns: page_ID, title, content, and url (a page slug)
I have an index.php page with the basic server-side setup I need
I already have the header, footer, config, and functions files created (where I require_once them in)

Now I was thinking about just writing up an SQL query in the body of the index file (This is the only display method I could find after searching for hours through dozens of Custom CMS tutorials):
PHP Code:
<?php

    $indexquery 
"SELECT content FROM Page";      
    
$indexresult mysql_query($indexquery$link) or die(mysql_error());

    while(
$row mysql_fetch_array($indexresult)){
        echo 
"<div id='webdescription'>" $row['content'];
        echo 
"</div>";
    }
?>
But the problem with this setup is that it retrieves data from every row in the content column, I don't want that. Then I thought about just adding a WHERE page_ID ='some_number' statement, which gives me what I want, but I'd have to create a php file for every single, and that's not good either.

I was trying out some test scripts to add to the file that might somehow change the URL based on page_ID, but I have no idea how to do that. The structure would look something along the lines of this, and I'd just mod_rewrite the url's later (they're not important for the time being):
http://www.site.com/index.php?=1

I also had Wordpress's system in mind when designing this, but couldn't see how they were doing it either.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
 
Register now for full access!
Old 07-13-2009, 09:50 PM Re: Creating a Database-Driven web page system
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
I'm about as experienced as you. To my knowledge though everything will be in one file index.php . Or a script will be included on that page.

Then you have something like

PHP Code:

    
<class="link">
      <
a href="{$_SERVER['PHP_SELF']}?=1">My first page!</a>
    </
p
You'll need a little more scripting around that though to point it to go to the page you want. I'm hoping to create a complete web site like the one you are explaining, but I'm still too inexperienced to do it.
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Old 07-14-2009, 02:56 PM Re: Creating a Database-Driven web page system
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Hey, thanks for looking into this too, Alex .

I suppose those "$_SERVER['something']" arrays are what I should be looking into.

The one you posted though doesn't actually go anywhere. It's reading the $_SERVER['PHP_SELF'] as if it were part of the actual file's pathname. I guess I have some more reading up to do on these different variable possibilities to use.

I was considering having just about everything (including the HTML) managed within the DB (except for the header and footer files, maybe those too, later down the road, once I understand the mechanics of DB / PHP integration). That way, I won't need all those different types of pages w/ dynamic links on them.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 07-14-2009, 04:32 PM Re: Creating a Database-Driven web page system
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
btw you didn't label the var passed

index.php?=1

should be

index.php?something=1

you can structure your table to have content based on an id or a name

then your php will call whatever is in that based on id or name

PHP Code:
<?php

    
//Getting The ID 
    
if (isset($_GET['id') && is_numeric($_GET['id'])) $id=$_GET['id'];
    else 
$id //1 is for index.php - like the home page
                                                             
   
    
$indexquery "SELECT content FROM Page WHERE id='$id'";      
    
$indexresult mysql_query($indexquery$link) or die(mysql_error());

    while(
$row mysql_fetch_array($indexresult)){
        echo 
"<div id='webdescription'>" $row['content'];
        echo 
"</div>";
    }
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 07-14-2009, 07:47 PM Re: Creating a Database-Driven web page system
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
I wasn't sure how to grab the ID like that, so that's what I was missing, thanks Jerry.



I don't suppose it's possible to use the same structure of code for getting the code with a function, is it?

I tried using the exact same lines for the title (except changing a few variable names around) and I get a mysql_query() supplied argument error).

It works fine without the function, but not when it's contained within one (and I'm not sure why either, as I've written a few other functions which are called and work just fine).
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects

Last edited by jamestl2; 07-14-2009 at 08:19 PM..
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 07-14-2009, 08:36 PM Re: Creating a Database-Driven web page system
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
hmmm i'm not sure what you're trying to get at... could you post a sample?

supplied arguement error is usually when you're looking at the tables for something a column that isn't there
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 07-14-2009, 10:00 PM Re: Creating a Database-Driven web page system
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Sure, (top of) index.php:
PHP Code:
<html>
    <head>
        <?php require_once ("config.php"); ?>
        <?php require_once ("functions.php"); ?>
    
    <title>
        <?php get_pagetitle(); ?>
    </title>
And functions.php:
PHP Code:
<?php
function get_pagetitle()
{
    
//Getting The ID 
    
if (isset($_GET['id']) && is_numeric($_GET['id'])) $id=$_GET['id'];
    else 
$id 1//1 is for index.php - like the home page
        
    
$titlequery "SELECT title FROM Site_Page WHERE ID = '$id'";
    
$titleresult mysql_query($titlequery$link); 
    
    while (
$title mysql_fetch_array($titleresult)) {
        echo 
$title['title'];
    }
    
    
mysql_free_result($titleresult);
    
}

?>
Which gives this error in the title:
Code:
Warning:  mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/site/public_html/webmasterdirectory/functions.php on line 9

Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/site/public_html/webmasterdirectory/functions.php on line 11
Like I said though, the exact code above, all one one page (index.php) works perfectly fine.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects

Last edited by jamestl2; 07-14-2009 at 10:04 PM..
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 07-14-2009, 10:06 PM Re: Creating a Database-Driven web page system
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
i could be wrong, I'm not at a computer to test this but I believe the functions need to be passed the arguements so your code should be like this

PHP Code:
<?php
//Getting The ID 
if (isset($_GET['id']) && is_numeric($_GET['id'])) $id=$_GET['id'];
else 
$id 1//1 is for index.php - like the home page
?>
<html>
    <head>
        <?php require_once ("config.php"); ?>
        <?php require_once ("functions.php"); ?>
    
    <title>
        <?php get_pagetitle($id); ?>
    </title> 

<?php   
    
function get_pagetitle($id)
{
    
        
    
$titlequery "SELECT title FROM Site_Page WHERE ID = '$id'";
    
$titleresult mysql_query($titlequery$link); 
    
    while (
$title mysql_fetch_array($titleresult)) {
        echo 
$title['title'];
    }
    
    
mysql_free_result($titleresult);
    
}
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 07-14-2009, 10:16 PM Re: Creating a Database-Driven web page system
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
I actually had the function on my functions.php page, but either way, it still gives the same error. I even tried passing it in my config.php file, but no luck, wherever I put it.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 07-15-2009, 01:36 AM Re: Creating a Database-Driven web page system
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
did you pass $link into the function? I don't see it anywhere
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 07-15-2009, 12:46 PM Re: Creating a Database-Driven web page system
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Quote:
Originally Posted by orionoreo View Post
did you pass $link into the function? I don't see it anywhere
You mean here?
PHP Code:
$titleresult mysql_query($titlequery$link); <----- 
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 07-25-2009, 01:40 AM Re: Creating a Database-Driven web page system
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
The function still doesn't want to work. I don't suppose there's any other ways to get this? I've been trying other tings to make it happen, like inserting a temporary static ID, yet I still get the darn supplied argument error . I'm thinking it's just a small syntax error, but I don't see it anywhere....

Also I forgot to mention, after looking over:
PHP Code:
<?php
//Getting The ID 
if (isset($_GET['id']) && is_numeric($_GET['id'])) $id=$_GET['id'];
else 
$id 1//1 is for index.php - like the home page
?>
I'm still not entirely clear on how this particular script "creates the different pages". I see that it fetches different ID's, but how does it "know" which one to get? I'm not entirely understanding the syntax to use and how it works in this instance. (If that makes any sense.)
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Reply     « Reply to Creating a Database-Driven web page system
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.85512 seconds with 12 queries