Jump to content

[SOLVED] simple code going wrong


supanoob

Recommended Posts

Basically i have a if statement with an echo below, which just isnt doing what it should, and i have used the same thing time and time again, any help?

 

if statement:

<?php if ($account_id > 0) {echo "<li class=\"last\"><a href=\"index.php?step=login\">Account</a></li>";} ?>

 

result:

Account";} ?

 

Link to comment
Share on other sites

Try this instead (easier to understand):

 

if ($account_id > 0) {
    echo "<li class='last'><a href='index.php?step=login'>Account</a></li>";
} 

 

that didnt solve my problem :S its uncluding some of the PHP

 

0) { echo "Account"; } ?>

 

After the actual if statment

Link to comment
Share on other sites

Also, does $account_id = a number or does it equal a "number" as in 0 and '0' are two different values ;)

 

That's only true when using ===, cause you're then checking type as well as value, but not with ==.

Link to comment
Share on other sites

Have you made sure the code surrounding that bit is all correctly closed/opened? Also, does $account_id = a number or does it equal a "number" as in 0 and '0' are two different values ;)

 

ill paste the whole page now:

 

<?php
$account_id = 1;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Website Name Not Decided</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>
<body>
<div id="wrap">
  <div id="header">
    <div id="header-links">
      <p> <a href="../index.php?step=news">News</a> | <a href="../index.php?step=register">Register</a> | <a href="../index.php?step=about">About</a> </p>
    </div>
  </div>
  <div  id="menu">
    <ul>
      <li id="current"><a href="../index.php">Home</a></li>
      <li><a href="../forums.php?step=main">Forums</a></li>
      <li><a href="../profiles.php?step=main">Profiles</a></li>
      <li><a href="../websites.php?step=main">Websites</a></li>
      <li><a href="../profiles.php?step=blogs">Blogs</a></li>
      <?php if ($account_id > '0') {
    echo "<li class='last'><a href='index.php?step=login'>Account</a></li>";
} ?>
     
    </ul>
  </div>
  <div id="content-wrap">
    <div id="sidebar">
      <h1>Search Box</h1>
      <form action="" class="searchform">
        <p>
        Search Forums:
          <input name="search_query" class="textbox" type="text" />
          <input name="search" class="button" value="Search" type="submit" />
        Search Profiles:
        <input name="search_query" class="textbox" type="text" />
          <input name="search" class="button" value="Search" type="submit" />
        </p>
      </form>
      <h1>Latest Forum Topics</h1>
      <ul class="sidemenu">
        <li><a href="">Post 1</a></li>
        <li><a href="">Post 2</a></li>
        <li><a href="">Post 3</a></li>
        <li><a href="">Post 4</a></li>
        <li><a href="">Post 5</a></li>
      </ul>
      <h1>Newest Members</h1>
      <ul class="sidemenu">
         <li><a href="">member 1</a></li>
        <li><a href="">member 2</a></li>
        <li><a href="">member 3</a></li>
      </ul>
      <h1>Site Statistics</h1>
      <div class="left-box">
        <p>Current Members: <br>
           Total Posts: <br>
           Online: <br>
           Current Websites: <br>
           </p>
      </div>
    </div>
    <div id="main"> 
    </div>
  </div>
  <div id="footer">
    <p> © 2006 <strong></strong> |  |  |         </p>
  </div>
</div>
</body>
</html>

Link to comment
Share on other sites

I CnP'd to my local and it looks fine, minus the CSS of course.

 

Sorry, I don't see anything that could be causing this.

 

if ($account_id > '0')  can you have a value that is greater than a text character?  i suppose it might compare it to the hex value of the character or something

 

but I am assuming you mean you want it greater than numerical zero in which case take off the ' '

 

I just tested it, it recognizes $account_id as greater than zero with or without the quotes.

Link to comment
Share on other sites

I CnP'd to my local and it looks fine, minus the CSS of course.

 

Sorry, I don't see anything that could be causing this.

 

if ($account_id > '0')  can you have a value that is greater than a text character?  i suppose it might compare it to the hex value of the character or something

 

but I am assuming you mean you want it greater than numerical zero in which case take off the ' '

 

I just tested it, it recognizes $account_id as greater than zero with or without the quotes.

 

so im assuming its something to do with the CSS?

Link to comment
Share on other sites

try to echo something simple..

 

if ($account_id > '0') {
  echo "Test.....";
}

 

then if ur echo content is static try keeping it as HTML

 

<?php 
if ($account_id > '0') { 
?>
    <li class='last'><a href='index.php?step=login'>Account</a></li>
<?php
} 
?>

Link to comment
Share on other sites

sorry, i thought it might have been a slightly different issue from the original post.

like Maq said the code snippet seems to work just fine.  can you post some of your CSS so we can try that and see if it affects it ?

 

/* Top Elements */
* { margin: 0; padding: 0; }

body {
background: #dadada;
font: 70%/1.5em Verdana, Tahoma, arial, sans-serif;
color: #555; 
text-align: center;
}

/* links */
a, a:visited {
text-decoration: none;
color: #2180BC;
background: inherit;
}
a:hover {
color: #88ac0b;
background: inherit;
text-decoration: underline;
}

h1, h2, h3, p {
padding: 10px;		
margin: 0;
}
ul, ol {
margin: 5px 20px;
padding: 0 20px;
}


quote {
  margin: 5px 0;
  padding: 10px;
  text-align: left;
  display: block;
  overflow: auto;  
  font: 500 1em/1.5em 'Lucida Console', 'courier new', monospace ;
  /* white-space: pre; */
  background: #FAFAFA;
  border: 1px solid #f2f2f2;  
}


/* end - table */

/* form elements */
form {
margin:10px; padding: 0 5px;
border: 1px solid #f2f2f2; 
background-color: #FAFAFA; 
}
label {
display:block;
font-weight:bold;
margin:5px 0;
}
input {
padding:2px;
border:1px solid #eee;
font: normal 1em Verdana, sans-serif;
color:#777;
}
textarea {
width:400px;
padding:2px;
font: normal 1em Verdana, sans-serif;
border:1px solid #eee;
height:100px;
display:block;
color:#777;
}
input.button { 
font: bold 12px Arial, Sans-serif; 
height: 24px;
margin: 0;
padding: 2px 3px; 
color: #FFF;
background: #8EB50C url(../images/layout/button-bg.jpg) repeat-x 0 0;
border: none;
}

/* search form */
.searchform {
background-color: transparent;
border: none;	
margin: 0; padding: 5px 0 15px 0;	
width: 190px;	
}
.searchform p { margin: 0; padding: 0; }
.searchform input.textbox { 
width: 120px;
color: #777; 
height: 18px;
padding: 2px;	
border: 1px solid #E5E5E5;
vertical-align: top;
}
.searchform input.button { 
width: 60px;
height: 24px;
padding: 2px 5px;
vertical-align: top;
}

/********************************************
   LAYOUT
********************************************/ 
#wrap {
width: 820px;
background: #CCC url(../images/layout/content_darkblue.jpg) repeat-y center top;
margin: 0 auto;
text-align: left;
}
#content-wrap {
clear: both;
width: 760px;
padding: 0; 
margin: 10px auto;
}
#header {
width: 820px;
position: relative;
height: 103px;
background: #CCC url(../images/layout/header_darkblue.jpg) no-repeat center top;
padding: 0;	
color: #FFF;
/* font-size: 14px; */
}

/* header links */
#header #header-links {
position: absolute;
top: 20px; right: 30px;	
color: #C6DDEE;
font-size: 10px;	
}
#header #header-links a {	
color: #FFF;
text-decoration: none;	
}
#header #header-links a:hover {
color: #D4E59F;	
}

/* Menu */
#menu {
clear: both;	
margin: 0 auto; padding: 0;
background: url(../images/layout/menu_darkblue.jpg) repeat-x 0 0;	
font: bold 12px/37px Verdana, Arial, Tahoma, Sans-serif;
height: 37px;
width: 780px;	
}
#menu ul {
float: right;
list-style: none;
margin:0; padding: 0;
}
#menu ul li {
display: inline;
}
#menu ul li a {
display: block;
float: left;
padding: 0 10px;
color: #FFF;	
text-decoration: none;
}
#menu ul li.last a {
padding-right: 20px;	
}
#menu ul li a:hover {
color: #D4E59F;	
}
#menu ul li#current a {	
color: #D4E59F;
}


.post-footer {
background-color: #FAFAFA;
padding: 5px; margin: 20px 10px 0 10px;
border: 1px solid #f2f2f2;
font-size: 95%;	
}

/* Sidebar */	
#sidebar {
float: right;
width: 26.5%;
padding: 0; margin: 0;	
color: #dadada;	
}	
#sidebar h1 {
margin-top: 10px;
padding: 5px 5px; 
font: bold 1.4em 'Trebuchet MS', Tahoma, Sans-serif;
color: #dadada;	
}
#sidebar ul.sidemenu {
list-style: none;
text-align: left;
margin: 7px 4px 8px 0; padding: 0;
text-decoration: none;
  color: #dadada;		

}
#sidebar ul.sidemenu li {
list-style: none;
color: #dadada;	
padding: 4px 0 4px 5px;
margin: 0 2px;	
color: #dadada;	
}
* html body #sidebar ul.sidemenu li {
height: 1%;
color: #dadada;	
}
#sidebar ul.sidemenu li a {
text-decoration: none;	
background-image: none;	
color: White;			
}
#sidebar ul.sidemenu li a:hover {	
color: #1773BC;	
}

/* Footer */	
#footer {
color: #C6DDEE;
background: #CCC url(../images/layout/footer_darkblue.jpg) no-repeat center top;
clear: both;
width: 820px;
height: 65px;
text-align: center;	
font-size: 92%;	
}
#footer a { 
color: #FFF;
text-decoration: none; 
}

/* alignment classes */
.float-left  { float: left; }
.float-right { float: right; }
.align-left  { text-align: left; }
.align-right { text-align: right; }

/* display and additional classes */
.clear { clear: both; }

 

thats my CSS

Link to comment
Share on other sites

try to echo something simple..

 

if ($account_id > '0') {
  echo "Test.....";
}

 

then if ur echo content is static try keeping it as HTML

 

<?php 
if ($account_id > '0') { 
?>
    <li class='last'><a href='index.php?step=login'>Account</a></li>
<?php
} 
?>

 

neither of those things changed anything, only what was echoed.

Link to comment
Share on other sites

Hey, I tested your script and put the CSS together.

In fact, the only wrong thing is to compare '0' to an integer,

but taking the quotes and passing it as zero,

I couldn't see any error.

 

NOTE: What browser are you using? 'Coz once a time when coding a site there was a time when the browser wasn't receiving the refresh from the server.

So I cleaned my temporary files and restarted the browser and everything went right again...

Link to comment
Share on other sites

Hey, I tested your script and put the CSS together.

In fact, the only wrong thing is to compare '0' to an integer,

but taking the quotes and passing it as zero,

I couldn't see any error.

 

NOTE: What browser are you using? 'Coz once a time when coding a site there was a time when the browser wasn't receiving the refresh from the server.

So I cleaned my temporary files and restarted the browser and everything went right again...

 

i have tried it on IE, FF and chrome and it shows the same thing on them all :S

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.