NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Function breaks out of the layout?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 06-28-2008, 08:23 AM THREAD STARTER               #1 (permalink)
Account Suspended
 
squid's Avatar
Join Date: Jan 2008
Location: Stafford
Posts: 993
squid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to behold
 


Special Olympics Myanmar Relief

Function breaks out of the layout?


Hi,
I have a function that echo's the navigation for a website, it runs perfectly, BUT, it breaks out of the layout. If i do;

PHP Code:
<div id="something"><?php eNavigation(); ?></div>
It "Breaks" out of the div and puts itself above everything else.

The function is;
PHP Code:
function eNavigation(){
$domain $_SERVER['HTTP_HOST'];
$NAVresult mysql_query("SELECT site FROM pages WHERE site='$domain' ORDER BY id ASC");  
while (
$NAVrow mysql_fetch_assoc($NAVresult)) {     
if (
$NAVrow['title'] == 'Home') {
????: NamePros.com http://www.namepros.com/programming/487005-function-breaks-out-of-the-layout.html
continue;     
}
echo 
"<li><a href=\"";
echo 
stripslashes($NAVrow['title']);
echo 
"\">";
echo 
stripslashes($NAVrow['title']);
echo 
"</a></li>";
}

Why does it break out of the Div?

So if i have;
PHP Code:
<html>
<head>
<title>hi</title>
</head>
<body>
<div id="something"><?php eNavigation(); ?></div>
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
</body>
</html>
When i view the page in my browser, the following happens;
PHP Code:
<NAVIGATION STUFF HERE>
<
html>
<
head>
<
title>hi</title>
</
head>
<
body>
<
div id="something"></div>
</
body>
</
html
squid is offline  
Old 06-28-2008, 08:30 AM   #2 (permalink)
NamePros Member
Join Date: May 2008
Posts: 181
blacknet is just really niceblacknet is just really niceblacknet is just really niceblacknet is just really niceblacknet is just really nice
 



PHP Code:
<?php
function eNavigation(){
$domain $_SERVER['HTTP_HOST'];
$NAVresult mysql_query("SELECT site FROM pages WHERE site='$domain' ORDER BY id ASC");  
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
$out '';
while (
$NAVrow mysql_fetch_assoc($NAVresult)) {     
if (
$NAVrow['title'] != 'Home') {
$out .= "<li><a href=\"";
$out .= stripslashes($NAVrow['title']);
$out .= "\">";
$out .= stripslashes($NAVrow['title']);
$out .= "</a></li>";
}
}
}
$injectthis eNavigation();
?>
<html>
<head>
<title>hi</title>
</head>
<body>
<div id="something"><?php echo $injectthis?></div>
</body>
</html>
not the best code, but will work and make page load faster..
blacknet is offline  
Old 06-28-2008, 11:55 AM   #3 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 99
Bruce_KD will become famous soon enoughBruce_KD will become famous soon enough
 



You're selecting the field site from your mysql database, but trying to print out the field title. I'm not sure if this is one of your issues or not, but it may be affecting the result.
Also, whats with the whole "if" "continue" thing...?


Bruce
Bruce_KD is offline  
Old 06-28-2008, 12:06 PM THREAD STARTER               #4 (permalink)
Account Suspended
 
squid's Avatar
Join Date: Jan 2008
Location: Stafford
Posts: 993
squid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to beholdsquid is a splendid one to behold
 


Special Olympics Myanmar Relief
Originally Posted by Bruce_KD
You're selecting the field site from your mysql database, but trying to print out the field title. I'm not sure if this is one of your issues or not, but it may be affecting the result.
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
Also, whats with the whole "if" "continue" thing...?


Bruce
The "title" is a field, so page ID 1 title = "something" page id 2 title = "something else" etc.

Also, i don't want it to echo the "home" one
squid is offline  
Old 06-28-2008, 12:10 PM   #5 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 99
Bruce_KD will become famous soon enoughBruce_KD will become famous soon enough
 



It doesn't matter what "title" is, if you aren't selecting it in your mySQL query, you can't call $row['title'].

Try
Code:
$NAVresult = mysql_query("SELECT title FROM pages WHERE site='$domain' ORDER BY id");
(ASC is the default order by, so you don't really need to include it).


Bruce
Bruce_KD is offline  
Old 06-29-2008, 03:12 AM   #6 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




blacknet, you're missing a
PHP Code:
return $out
a
PHP Code:
$out '<ol>'
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
and a
PHP Code:
$out '</ol>'
in that function, also.
Barrucadu is offline  
Old 06-29-2008, 07:50 AM   #7 (permalink)
NamePros Member
Join Date: May 2008
Posts: 181
blacknet is just really niceblacknet is just really niceblacknet is just really niceblacknet is just really niceblacknet is just really nice
 



Alas, it was only a quick 2 seconds code whilst on the phone and after being awake for way too long.

As you'll know there are tonnes of mistakes in the whole thing. Anyways, this may be of more help.. you'll still need to connect up to your db etc and everything else you need to do lol.

PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=487005

function eNavigation(){
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
    
$htmlNav '';
    if( 
$navResult select("SELECT site, title FROM pages WHERE site='" cleansegetHostDomain() ) . "' ORDER BY id ASC") ) {
        foreach( 
$navResult as $index => $values ) {
            if( 
trim(strtolower$values['title'] )) !== 'home' ) {
                
$htmlNav .= '<li><a href="'$values['title'] .'">'$values['title'] .'</a></li>';
            }
        }
    }
    return (bool)
strlen($htmlNav) ? '<ol>' $htmlNav '</ol>' '';
}

function 
getHostDomain() {
    
// it's preferable to user SERVER_NAME over HTTP_HOST
    // as HTTP_HOST is only present in valid HTTP 1.1 calls
    // even more preferable is to define the current host in a config file
    
$domain strtolowertrim $_SERVER['SERVER_NAME'] ) );
    return (
substr($domain04) == 'www.') ? substr$domain 4) : $domain;
}

function 
select$query ) {
    
// a quick select function
    // always best to get resources freed up as quickly as possible.
    
$result mysql_query$query ) or die( 'Query failed: ' mysql_error() . "\n" $query );
    
$result_rows mysql_num_rows$result );
    if (
$result_rows == 0) {
        return 
FALSE;
    }
    
$output = array();
    for (
$r=0;$r<$result_rows;$r++) {
       
$output[$r] = mysql_fetch_assoc($result);
    }
    
mysql_free_result($result);
    return 
$output;
}

function 
cleanse$var ) {
    
// quick function to cleanse our variables for use in query strings
    // prevent sql injection attacks etc
    
if( function_exists('mysql_real_escape_string') ) {
        if( 
function_exists('get_magic_quotes_gpc') ) {
           
$var get_magic_quotes_gpc() ? stripslashes($var) : $var;
        }
        
// function will only work if a mysql connection is active..
        
return @mysql_ping() ? mysql_real_escape_string$var ) : $var;
    }
    return 
$var;
}

$navigation eNavigation();
?>
<html>
<head>
<title>hi</title>
</head>
<body>
<div id="something"><?php echo $navigation?></div>
</body>
</html>
is probably a more useful response *shrugs*
blacknet is offline  
Old 06-29-2008, 09:25 AM   #8 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
My contribution

Instead of:
PHP Code:
function getHostDomain() {
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
    
// it's preferable to user SERVER_NAME over HTTP_HOST
    // as HTTP_HOST is only present in valid HTTP 1.1 calls
    // even more preferable is to define the current host in a config file
    
$domain strtolowertrim $_SERVER['SERVER_NAME'] ) );
    return (
substr($domain04) == 'www.') ? substr$domain 4) : $domain;

Use:
PHP Code:
function getHostDomain() {
    
// it's preferable to user SERVER_NAME over HTTP_HOST
    // as HTTP_HOST is only present in valid HTTP 1.1 calls
    // even more preferable is to define the current host in a config file
????: NamePros.com http://www.namepros.com/showthread.php?t=487005
    
$domain strtolowertrim $_SERVER['SERVER_NAME'] ) );
    return 
preg_replace('#^www\.#'''$domain);

Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:53 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger