SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old May 10th, 2002, 09:02 PM
MuuTuwon MuuTuwon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN, USA
Posts: 25 MuuTuwon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MuuTuwon Send a message via AIM to MuuTuwon
Beginner needing help with a problem.


As the subject states, I'm a beginner in PHP, and what I know I have taught myself. So in other words if what I'm trying to do is just, completely and totatlly wrong, you know why.

Basicly I'm having trouble with a script I'm writing to be a generic website backend. It uses PHP and MySQL. The SQL database (at the moment) has two tables, one that holds the site's template, and another that holds the unique part of the code for each individual page and an ID.

There is an index page that calls and echos the code field of the template. The code of the template in turn calls and echos the individual pages based on the $show variable. So basicly its a code, that calls another set of code, that calls another set of code, which is where my trouble is. The reason I dont' just have the template page static is so that it can be edited via online form through the site's backend. The problem I have though is that the code in the templete, when called to the index page, doesn't registar as PHP code. Rather it just prints the code as if there were no tags around it.

Why is this? is it possible to put php script inside an SQL database, echo it, and expect it to run? Let alone stack 3 layers of this as I'm attempting to do?

If you need anymore information I'd be more then happy to apply with what you need. I can't link to where the code is on my webserver because the directory is secure. But I'd find it acceptable to post parts of the code if nesscary. Also contact over e-mail and ICQ messages is welcome.

Thanks in advance for providing a place to ask for help. As of yet in teaching myself PHP if I stuck with it long enough I've been able to figure out my own problems, but this one really has me jumping through hoops.

Thanks Again,
-MuuTuwon

Reply With Quote
  #2  
Old May 10th, 2002, 09:22 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Beginner needing help with a problem.

Try something like this:

php Code:
Original - php Code
  1.  
  2. <?
  3. $db = mysql_connect('localhost','*****','******');
  4. $query = "SELECT template FROM templates";
  5. $template = $row['template'];
  6. $query = "SELECT page FROM pages WHERE id=$page";
  7. $page = $row['page'];
  8. $display = str_replace("<-insert page here->",$page,$template);
  9. eval($display);
  10. ?>


All you need to do is in your template, where there page code should be inserted, add:

<-insert page here->

Really, the eval() function is the whole heart of the thing....

Reply With Quote
  #3  
Old May 11th, 2002, 05:06 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: Beginner needing help with a problem.

I like the way how that works. Matt maybe you could do a tutorial on how to do it?

Reply With Quote
  #4  
Old May 12th, 2002, 12:33 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Beginner needing help with a problem.

I've put it on my list


Reply With Quote
  #5  
Old May 12th, 2002, 07:11 AM
MuuTuwon MuuTuwon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN, USA
Posts: 25 MuuTuwon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MuuTuwon Send a message via AIM to MuuTuwon
Thanks

Thanks for the help, unfortinatly it didn't work out but I think that may be because of my own inabilty to understand the function correctly.

I had to change several parts of the code to fit my table structure in SQL, I don't know how much of an effect that would have on it but I'm including the code this time to see if I've done something wrong.

And also, what exaclty does the eval() function do? just for personal reference so I may be able to use it in the future?

<?php

$db = mysql_connect('www.doomland.net','****','****') or die("could not connect to database");

mysql_select_db('test') or die("could not select database");

$query = "SELECT * FROM sitemain WHERE id ='template'";

$row = mysql_fetch_array(mysql_query($query));

$template = $row['code'];

$query = "SELECT code FROM sitemain WHERE id='$show'";

$row = mysql_fetch_array(mysql_query($query));

$page = $row['code'];

$display = str_replace("<-insert page here->",$page,$template);

eval($display);

?>

Any suggestions welcome.

-MuuTuwon

Reply With Quote
  #6  
Old May 12th, 2002, 09:07 PM
Christoph2k Christoph2k is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 14 Christoph2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Beginner needing help with a problem.

Do you mean that you store variables e.g. $variable in a MySQL database?
Because if you do, then PHP will think that it is just text! The only thing you could do is store numbers instead of variables, and use a string replace to replace the variable with the value! But its pretty pointless.
You could try and cut out the middle script, you said that it was linked between 3 script!

Thanxs
Christoph Neal
London, UK
Chris@n-12.net
www.n-12.net

Reply With Quote
  #7  
Old May 12th, 2002, 09:11 PM
Christoph2k Christoph2k is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 14 Christoph2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Beginner needing help with a problem.

Pay NO attention to what i just said!

Reply With Quote
  #8  
Old May 12th, 2002, 09:33 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: RE: Beginner needing help with a problem.


Quote:
I've put it on my list


how long is your list now matt?

Reply With Quote
  #9  
Old May 13th, 2002, 03:02 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Beginner needing help with a problem.

Too long

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Beginner needing help with a problem.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway