homepage Welcome to WebmasterWorld Guest from 54.167.174.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
One Size Fits All Script for Page Output - PHP
Just can't sort it out
brotherhood of LAN

WebmasterWorld Administrator brotherhood_of_lan us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 543 posted 6:33 pm on Aug 28, 2002 (gmt 0)

I want to make a PHP script that will be uniform over a wide number of pages, where all variables will be determined by information contained in a mySQL database. All good.

Basically there will be 3 divs, absolutely positioned, and the current mySQL table outputs these variables to the page are (in order of appearance) ;)

<head>title,description,keywords,path-to-css</head>
<body>centre div content -- the meat, left divpagecontent, right divpagecontent</body>

All is good to this PHP newbie. The thing is with the tutorials, each tutorial has a "tutorialid" that is meant to signify what "include" to use per tutorial....to be used for navigation.

The query > $result = mysql_query("SELECT title,description,keywords,style,c FROM tutorials WHERE path='$REQUEST_URI'");

The output of the query looks like this

do { printf("
<title>%s</title>
<meta name=\"description\" content=\"%s\">
<meta name=\"keywords\" content=\"%s\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"/inc/%s.css\">
</head><body><div id=\"T\"><h1>Spam</h1><h4>Smaller spam</h4></div>
<div id=\"C\">%s</div>
", $myrow["title"],$myrow["description"],$myrow["keywords"],$myrow["style"],$myrow["c"]);
} while ($myrow = mysql_fetch_array($result));
}

The left and right divs are missing, because I had probs adding the includes.....no doubt because you can't do that in a "printf" function :).

Ideally, the divs would look like this.

<div id="L">
include ("$inc_id.inc")
<!--Plus another row from mySQL-->
</div><div id="R">
include ("regularinclude.inc")
<!--Plus another row from mySQL-->
</div>

The variable mentioned above can be acquired from the same table used in the mySQL query posted above. I just have no idea how to implement this into the same script, if thats at all possible, or whether some tweaking should be done to the query or the structure of the table itself.

inc_id ord_id path title description keywords style C
1¦1¦theURI¦Thetitle¦metadescription¦metakeywords¦stylesheetfilename¦themeatycontent

2 more columns will be added for the "plus another row" bits mentioned above!

Anyway, the point of this long post is essentially, I can't figure out the syntax to insert the variable inside the L DIV.

What can be done about this ..... I've scanned many of the docs over the past few weeks (just starting to learn it) and this is me at a bottleneck.

If I can get the above to work it will mean I can publish this script to all the tutorial pages and not have to bother about future changes. Help would be very much appreciated

Richard

 

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 543 posted 7:09 pm on Aug 28, 2002 (gmt 0)

alright BOL,

I'm confused, I will go over a few points again to see if I am understanding correctly. First DB structure,

inc_id - what is this?
ord_id - what is this?
path - OK
title - OK
description - OK
keywords - OK
style - OK
C - OK
L - to be added for left div content?
R - to be added for right div content?

primarily I don't get the two id's (inc_id and ord_id). I see inc_id is used in the include for the left content. If you are including the column that will have the left content in the table this could be extra. I can only assume that ord_id is just a primary key type index.

brotherhood of LAN

WebmasterWorld Administrator brotherhood_of_lan us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 543 posted 7:25 pm on Aug 28, 2002 (gmt 0)

Confused? Join the club, I've been this way for weeks and thinking about a script like this. It's just my lack of knowledge of PHP, probably making an easy job look hard.

I was going to mention the ord_id bit. This is for future reference if I ever need to output the ORDer of the pages in a particular tutorial.

The inc_id bit is a reference to what tutorial the page is in. I have 9 tutorials, thus an "inc_id" from 1 to 9. Each tutorial has an include that have navigation from page A to Z of each tutorial.

So, if a visitor was looking at tutorial "1"....then I'd hope to include the navigation for tutorial one in div L.

ie this is why I want include($inc_id.inc) sort of thing.....the navigation will appear according to the inc_id of the tutorial page.

The L and R bits are for pieces of information that may appear on one page but not all of them.

ie...you are on tutorial 1 page 1
content shows in Div C for page 1
navigation shows in div L for tutorial 1
Div R will have sitewide navigation.

For "L" and "R" in the SQL table....this is if I want to add some more information that would otherwise not fit well into a database.

i.e. tutorial 1 page 1 might have a few affiliate links that I only want to appear in that page. Otherwise its a case of me getting flummoxed and not knowing how else to fit in unique data into these divs.

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 543 posted 7:35 pm on Aug 28, 2002 (gmt 0)

have you looked through this thread
Simple Content Switching with PHP Variables [webmasterworld.com]?

It addresses the include ("$inc_id.inc") issue. I would also select * from..... for your query. Then you will have all of the info you need to build your page.

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 543 posted 7:52 pm on Aug 28, 2002 (gmt 0)

You might want to either make use of the a) return value of the include function or b) split up your printf statement.

a) As explained in [php.net...] it is possible to have the included file return a value. Using this feature your code might look like this:

do { printf('  
<title>%s</title>
<meta name="description" content="%s">
<meta name="keywords" content=\"%s">
<link rel="stylesheet" type="text/css" href="/inc/%s.css">
</head><body><div id="T"><h1>Spam</h1><h4>Smaller spam</h4></div>
<div id="C">%s</div>
<div id="L">%s</div>
<div id="R">%s</div>
',
$myrow["title"],$myrow["description"],$myrow["keywords"],
$myrow["style"],$myrow["c"],
// [edited]
include($myrow["inc_id"].".inc"),
// [/edited]
include("regularinclude.inc"));
} while ($myrow = mysql_fetch_array($result));

In any case notice the use of the single quotes to delimit the printf string and how much nicer the string looks without having to escape all those double quotes.

All you need to do is make sure that the included files don´t output anything but return it instead. You can achieve that without having to rewrite the include files by using php´s output control functions [php.net] (start buffering [php.net], get content of buffer [php.net], erase buffer [php.net]).

b) split up your printf statement

do { printf(' 
<title>%s</title>
<meta name="description" content="%s">
<meta name="keywords" content=\"%s">
<link rel="stylesheet" type="text/css" href="/inc/%s.css">
</head><body><div id="T"><h1>Spam</h1><h4>Smaller spam</h4></div>
<div id="C">%s</div>
<div id="L">
',
$myrow["title"],$myrow["description"],$myrow["keywords"],
$myrow["style"],$myrow["c"]);
include($myrow["inc_id"].".inc");
printf('
</div>
<!-- anything else -->
</body>
', $anything_else_vars
);
} while ($myrow = mysql_fetch_array($result));

[edited by: andreasfriedrich at 10:16 pm (utc) on Aug. 28, 2002]

Nick_W

WebmasterWorld Senior Member nick_w us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 543 posted 8:08 pm on Aug 28, 2002 (gmt 0)

Check out the Smarty template system [smarty.php.net] then just create a template with these vars all on it and call it with a functions once you've gathered all the values from the db...

Nick

brotherhood of LAN

WebmasterWorld Administrator brotherhood_of_lan us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 543 posted 9:04 pm on Aug 28, 2002 (gmt 0)

Thanks for the sound suggestions so far.

andreasfriedrich, I went for your first example. All good....but..

The variable for inc_id does not get returned.....it doesn't seem to take the variable into account so PHP starts looking for a file called .inc rather than 1.inc

Also, the includes seem to want to be included first and foremost - that is, above the title,description etc.

I'll be looking at all those other references.

Jatar, is the answer in that other thread? It read confusing to me.....and all that unique code/rewrites of it didn't help too much :)

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 543 posted 9:50 pm on Aug 28, 2002 (gmt 0)

check the lower part of ergophobe's post#11 in that thread.

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 543 posted 10:14 pm on Aug 28, 2002 (gmt 0)

Sorry, my mistake. Have a look at the edited post above.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved