Jump to content

Oh dear...


Aureole

Recommended Posts

I have something that is worked out later on in the page, say 3/4 of the way down...but a script I have (that needs to go in the <head>) needs to know the thing that is worked out in order to function...

 

Is there any way with php to change the <head> after something has been queried and worked out... and in case you ask, it's not possible for this query to go before the javascript at all.

Link to comment
Share on other sites

Well, hackish solution is to use output buffering, and if you later in the page needs to insert something into the page, just modify what's in the buffer. However, the good solution is to structure your web pages in such manner, that all the output comes after the code logic, so that when you start outputting, you already know everything there is to output.

Link to comment
Share on other sites

I have found a way around this (believe it or not)... so nevermind. ;D

 

But I'd still like to know, is something like this possible and if so how difficult is it?

I generally try pushing all output to the end of my script.  I do all my calculations first before anything goes to the screen.

 

Here's the basic structure.

 

<?php

// filter POST and GET data, if any

// run queries based on filtered data

// process all necessary information for output

?>
<html>
<head>
<title>
<?=$page_title?>
</title>
</head>

<body>

<!-- lots of html -->
<?php
// some php
?>


</body>
</html>

Link to comment
Share on other sites

Are you doing something like this?

 

<?php

// lots of code omitted
// query to grab a page worth of posts
$result = mysql_query($sql);

?>

<html>

<?php
// display posts
while($row = mysql_fetch_assoc($result))
{
  // do error checking here
  // display post
}
?>

</html>

Link to comment
Share on other sites

It's probably very messy but it works for me...

 

<?php
session_start();

include('functions.swr3');
include('config.swr3');

dbConnect();

if(SOFTWARE_OFFLINE == 1) {
    if(!isAdmin()) {
    header('Location: offline.swr3');
}
    elseif(!isSuperMod()) {
  	    header('Location: offline.swr3');
        }
}
if (userLogged()) {
    updateLastAction($_SESSION['mem_id']);
updateWhere($_SESSION['mem_id'], 'viewing the Forum Index');
}

$pagetitle = 'Forum';
$navcurrent = 'Forum';

include('inc/header.swr3');
?>

    <div id="breadcrumbs"><p class="breadcrumbs"><a href="index.swr3" class="forum_title_a" title="Go to the Homepage.">SW Revolution 3</a> > Forum</p></div>

    <div class="clearfix"><!--No Content--></div>

<div class="column">

<?php
$query ="SELECT * FROM categories WHERE cat_visible='1' ORDER BY cat_id";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_assoc($result)) {
    $c_id = $row['cat_id'];
$c_name = $row['cat_name'];
?>

        <div class="con_forum_outer">

        <div class="con_forum_title">
        <a href="viewcategory.swr3?id=<?php echo $c_id; ?>" class="cat_title_a" title="View this Category."><?php echo $c_name; ?></a>
        </div>

        <div class="con_forum_inner">

           <table class="forum_table" cellspacing="1">

                <tr>
                    <th width="50%" class="forum_th">Forum</th>
                    <th width="10%" class="forum_th">Topics</th>
                    <th width="10%" class="forum_th">Replies</th>
                    <th width="30%" class="forum_th">Last Post</th>
                </tr>

<?php
    $query ="SELECT * FROM forums WHERE forum_parent_id='{$c_id}'";
    $resulttwo = mysql_query($query) or die(mysql_error());

    while($row = mysql_fetch_assoc($resulttwo)) {
    $f_id = $row['forum_id'];
        $f_name = $row['forum_name'];
    $f_desc = $row['forum_description'];
    $f_topics = $row['forum_topics'];
    $f_replies = $row['forum_replies'];
?>
                <tr>
                    <td width="50%" style="background-color:#242424;padding:5px;"><p class="forum_desc"><a href="viewforum.swr3?id=<?php echo $f_id; ?>" class="forum_title_a" title="View this Forum."><?php echo $f_name; ?></a><br /><?php echo $f_desc; ?></p></td>
                    <td width="10%" style="text-align:center;background-color:#242424;"><p class="content"><?php echo $f_topics; ?></p></td>
                    <td width="10%" style="text-align:center;background-color:#242424;"><p class="content"><?php echo $f_replies; ?></p></td>
                    <td width="30%" style="background-color:#242424;padding:5px;"><p class="content"><?php if($f_topics == 0) { echo('No Topics!'); } ?></p></td>
                </tr>
<?php
    }
?>
            </table>

        </div>

        </div>
<?php
}
?>

        <div class="con_forum_outer" style="margin:0;">

        <div class="con_forum_title">
        <h1>Statistics</h1>
        </div>

        <div class="con_forum_inner">

<?php
$query = "SELECT topic_id FROM `topics`";
$result = mysql_query($query) or die(mysql_error());
$total_topics = mysql_num_rows($result);

$query = "SELECT reply_id FROM `replies`";
$result = mysql_query($query) or die(mysql_error());
$total_replies = mysql_num_rows($result);

$total_posts = $total_topics + $total_replies;

$query = "SELECT mem_id FROM `members`";
$result = mysql_query($query) or die(mysql_error());
$total_members = mysql_num_rows($result);

$query = "SELECT * FROM `members` INNER JOIN groups on members.mem_group=groups.group_id ORDER BY mem_id DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
    $lm_group_color = $row['group_color'];
$lm_group_font_weight = $row['group_font_weight'];
$lm_group_font_size = $row['group_font_size'];
$lm_group_text_decoration = $row['group_text_decoration'];
$latest_member_dname = $row['mem_dname'];
$latest_member_id = $row['mem_id'];
}

$query = "SELECT * FROM `members` INNER JOIN groups on members.mem_group=groups.group_id WHERE mem_online='1' ORDER BY mem_dname ASC";
$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
    $group_color = $row['group_color'];
$group_font_weight = $row['group_font_weight'];
$group_font_size = $row['group_font_size'];
$group_text_decoration = $row['group_text_decoration'];

    $online_members .= '<a href="profile.swr3?id='.$row['mem_id'].'" style="color:'.$group_color.';font-size:'.$group_font_size.'px;font-weight:'.$group_font_weight.';text-decoration:'.$group_text_decoration.';" title="View '.$row['mem_dname'].'\'s Profile.">'.$row['mem_dname'].'</a>, ';
}

if(mysql_num_rows($result) == 0) {
    $online_members = 'There are no Members currently online.';
} else {
    $online_members = substr($online_members, 0, -7);
}
?>
            <table class="forum_table" cellspacing="1">

                <tr>

                    <th width="100%" class="forum_th_left">Online Members</th>

                </tr>

                <tr>

                    <td width="100%" style="background-color:#242424;padding:5px;"><p class="forum_desc"><?php echo $online_members; ?></p></td>

                </tr>

                <tr>

                    <th width="100%" class="forum_th_left">Forum Stats</th>

                </tr>

                <tr>

                    <td width="100%" style="background-color:#242424;padding:5px;"><p class="forum_desc">Our members have made a total of <?php echo $total_posts; ?> Posts<br /><?php echo $total_topics; ?> Topics and <?php echo $total_replies; ?> Replies<br />We have <?php echo $total_members; ?> Members<br />The newest Member is: <a href="profile.swr3?id=<?php echo $latest_member_id; ?>" style="color:<?php echo $lm_group_color; ?>;font-size:<?php echo $lm_group_font_size; ?>px;font-weight:<?php echo $lm_group_font_weight; ?>;text-decoration:<?php echo $lm_group_text_decoration; ?>;" title="View <?php echo $latest_member_dname; ?>'s Profile."><?php echo $latest_member_dname; ?></a><br /></p></td>

                </tr>

            </table>

</div>
</div>

       </div><!--end column-->
       
       
       
    <div class="clearfix"><!--No Content--></div>
    
    <div id="leftcolumn">

        <div class="con_2_outer">

        <div class="con_2_title"><h1>Header</h1></div>

            <div class="con_2_inner">
                <p class="content">Content.</p>
            </div>

        </div>

        <div class="con_2_outer">

        <div class="con_2_title"><h1>Let's add another</h1></div>

            <div class="con_2_inner">
                <p class="content">Content.</p>
            </div>

        </div>

        <div class="con_2_outer">

        <div class="con_2_title"><h1>One more for good measure</h1></div>

            <div class="con_2_inner">
                <p class="content">Content.</p>
            </div>

        </div>

        <div class="con_2_outer">

        <div class="con_2_title"><h1>Hell, why not one more</h1></div>

            <div class="con_2_inner">
                <p class="content">Content.</p>
            </div>

        </div>

        <div class="clearfix"><!--No Content--></div>

    </div>

    <div id="rightcolumn">

        <div id="menu_outer">

            <div id="menu_inner">

                <div id="menu_title_first">Menu Header</div>
                <div class="menu_item">Menu Item</div>
        
                <div class="menu_title">Menu Header</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
        
                <div class="menu_title">Menu Header</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
        
                <div class="menu_title">Menu Header</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>
                <div class="menu_item">Menu Item</div>

            </div>

        </div>

        <div class="clearfix"><!--No Content--></div>

    </div>

<?php
include('inc/footer.swr3');
?>

 

All the empty menu stuff at the bottom is just there as I was testing some IE bug out where if the page doesn't have enough content to scroll then it juts to the left..so I added a crap load of content... until I work it out.

Link to comment
Share on other sites

Now that you have it working, you might want to go and clean it up a bit.  Break pieces down into functions or something because intermingling PHP & HTML that much becomes difficult to read very fast.  Throw in some CSS and Javascript and you have a perfectly unmaintainable site.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.