[advanced search]
Results from the most recent live auction are here.
16 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 06-28-2008, 07:23 AM   · #1
squid
Account Suspended
 
squid's Avatar
 
Name: Sam Ryan
Location: Stafford
Trader Rating: (51)
Join Date: Jan 2008
Posts: 993
NP$: 15.00 (Donate)
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') {
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>
</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>


Please register or log-in into NamePros to hide ads
squid is offline   Reply With Quote
Old 06-28-2008, 07:30 AM   · #2
blacknet
NamePros Member
 
Trader Rating: (17)
Join Date: May 2008
Posts: 178
NP$: 85.00 (Donate)
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");  
$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   Reply With Quote
Old 06-28-2008, 10:55 AM   · #3
Bruce_KD
NamePros Member
 
Trader Rating: (1)
Join Date: Sep 2006
Posts: 78
NP$: 100.00 (Donate)
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   Reply With Quote
Old 06-28-2008, 11:06 AM   · #4
squid
Account Suspended
 
squid's Avatar
 
Name: Sam Ryan
Location: Stafford
Trader Rating: (51)
Join Date: Jan 2008
Posts: 993
NP$: 15.00 (Donate)
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.
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   Reply With Quote
Old 06-28-2008, 11:10 AM   · #5
Bruce_KD
NamePros Member
 
Trader Rating: (1)
Join Date: Sep 2006
Posts: 78
NP$: 100.00 (Donate)
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   Reply With Quote
Old 06-29-2008, 02:12 AM   · #6
Barrucadu
Formally Mikor.
 
Barrucadu's Avatar
 
Name: Michael Walker
Location: East Yorkshire, England
Trader Rating: (7)
Join Date: Aug 2005
Posts: 2,546
NP$: 171.25 (Donate)
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>';
and a
PHP Code:
$out = '</ol>';
in that function, also.
__________________
Me | Last.fm | F@h | Archlinux.co.uk

archlinux User
Barrucadu is offline   Reply With Quote
Old 06-29-2008, 06:50 AM   · #7
blacknet
NamePros Member
 
Trader Rating: (17)
Join Date: May 2008
Posts: 178
NP$: 85.00 (Donate)
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

function eNavigation(){
    
$htmlNav = '';
    if(
$navResult = select("SELECT site, title FROM pages WHERE site='" . cleanse( getHostDomain() ) . "' 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 = strtolower( trim ( $_SERVER['SERVER_NAME'] ) );
    return (
substr($domain, 0, 4) == '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   Reply With Quote
Old 06-29-2008, 08:25 AM   · #8
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 
Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,239
NP$: 384.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
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 Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
My contribution

Instead of:
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
    
$domain = strtolower( trim ( $_SERVER['SERVER_NAME'] ) );
    return (
substr($domain, 0, 4) == '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
    
$domain = strtolower( trim ( $_SERVER['SERVER_NAME'] ) );
    return
preg_replace('#^www\.#', '', $domain);
}
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.2 now available!!
MetaCreator.com - Free Meta Tag Creator
CodingPlanet.com - Coming soon...
SecondVersion is offline   Reply With Quote
Reply

NamePros is a revenue sharing forum.

Thread Tools

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
Forum Jump


Site Sponsors
Exdon http://www.mobisitetrader.com/ YUPPADS
Advertise your business at NamePros
All times are GMT -7. The time now is 10:46 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0