Page 1 of 1
Help checking code
Posted: Wed Nov 04, 2009 4:48 am
by Parisij
okay this code is supposed to display hunger based on the number in the database. so if the number 4 is in the database under hungry... then it should be displayed that the character is not hungry... if 1 is in the database under hungry it should be displayed starving...
Now i changed the number in the database to 1 from 4 and it still displays not hungry...
what have i done wrong?
Code: Select all
<?php
echo "<b><big><u>Hungry</u></big></b><br>";
if ($playerinfo3['hungry'] = '4'):
{
echo "Not Hungry";
}
elseif ($playerinfo3['hungry'] = '3'):
{
echo "Hungry";
}
elseif ($playerinfo3['hungry'] = '2'):
{
echo "Very Hungry";
}
elseif ($playerinfo3['hungry'] = '1'):
{
echo "Starving";
}
endif;
?>
Re: Help checking code
Posted: Wed Nov 04, 2009 6:00 am
by alexrules01
Do you have the code that retrieves the players information? Because what you have written there, its not getting the data from the player
Re: Help checking code
Posted: Wed Nov 04, 2009 6:13 am
by Parisij
Yes, this is an include file that is included just below the retrieval of players information.
Let me get where its included.. or an example of one of the pages its included on
but before I do that, this is the whole include file:
Code: Select all
<div id="gold">
<?php
echo "<b><big><u>Gold</u></big></b><br>";
echo $playerinfo3['gold'];
?>
</div>
<div id="activity">
<?php
echo "<b><big><u>Activity</u></big></b><br>";
echo $playerinfo3['activity'];
?>
</div>
<div id="hungry">
<?php
echo "<b><big><u>Hungry</u></big></b><br>";
if ($playerinfo3['hungry'] = '4'):
{
echo "Not Hungry";
}
elseif ($playerinfo3['hungry'] = '3'):
{
echo "Hungry";
}
elseif ($playerinfo3['hungry'] = '2'):
{
echo "Very Hungry";
}
elseif ($playerinfo3['hungry'] = '1'):
{
echo "Starving";
}
endif;
?>
</div>
Now this is one of the pages that it is included on:
Code: Select all
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php'; //// normal part of tutorial
include_once 'session.php'; /// this inlude file does the player retrieval and the get session stuff
include_once 'playerinfo.php'; ///this is the inlcude file for gold, hungry, activity
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">
</div>
<div id ="locations">
<?php
$playerhp = $playerinfo3['hitpoints'];
if ($playerhp < 1)
{
echo "You are dead!" ;
echo "<br><a href='useitem.php>Use an Item";
exit;
}
echo "<b><big><u>Locations</u></big></b><br>";
echo "<a href='home.php'>House<br></a>";
echo "<a href='townhall.php'>Town Hall<br></a>";
echo "<a href='blacksmith.php'>Blacksmith<br></a>";
echo "<a href='Merchant.php'>Merchant<br></a>";
echo "<a href='jobs.php'>Find Jobs<br></a>";
?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'></a>";
?>
</div>
Just so you know the gold and activity... actually just the gold... i cant alter activity yet... the gold updates nicely... but the hungry is not updating I believe it has to do with the code I posted in my first post.
Code: Select all
<?php
echo "<b><big><u>Hungry</u></big></b><br>";
if ($playerinfo3['hungry'] = '4'):
{
echo "Not Hungry";
}
elseif ($playerinfo3['hungry'] = '3'):
{
echo "Hungry";
}
elseif ($playerinfo3['hungry'] = '2'):
{
echo "Very Hungry";
}
elseif ($playerinfo3['hungry'] = '1'):
{
echo "Starving";
}
endif;
?>
Re: Help checking code
Posted: Wed Nov 04, 2009 6:22 am
by alexrules01
Wait, do you need the : ?
I'm pretty sure I don't have the semi-colon at the end of the lines if ($playerinfo3['hungry'] = '4') :
Re: Help checking code
Posted: Wed Nov 04, 2009 11:49 am
by Torniquet
Code: Select all
<?php
echo "<b><big><u>Hungry</u></big></b><br>";
if ($playerinfo3['hungry'] == '4')
{
echo "Not Hungry";
}
elseif ($playerinfo3['hungry'] == '3')
{
echo "Hungry";
}
elseif ($playerinfo3['hungry'] == '2')
{
echo "Very Hungry";
}
elseif ($playerinfo3['hungry'] == '1')
{
echo "Starving";
}
?>
When working with if statments and a condition is to equal a specific vallue. you must always have 2 equal signs.
you don't need the endif statement. and as alex pointed out you dont need the semi-colon (nor a colon as that what was put down :p) at the end of the if statements.
also might i suggest changing the 1st Hungry to Hunger, the heading one.
Re: Help checking code
Posted: Wed Nov 04, 2009 1:15 pm
by Parisij
That worked!!
Thank you...
I shoulda actually realized this...
But thank you
