Jump to content

[SOLVED] Can't find out why it does option A although it should do option B


DEVILofDARKNESS

Recommended Posts

If I run this script with user Test that has leader: no,

I get: This nation doesn't have any weapons.

Although I should get This: You don't have any weapons...

 

I echoed $leader on an other page and it gave as output: no (which it should be),

but if I echo it on the page it gives: yes

although it is the same code which generates if it is a leader or not.

I'm a bit confused???

 

(You should actually only see to the last lines of the code, not to the query, the query is only loaded when there are results found, in this case their aren't...)

 

weapons.php

<?php
session_start();
require_once './config.php';
require_once './checkuserid.php';

$query = "SELECT leader FROM users WHERE user_id = '$userid'";
$result = mysql_query($query);
list($leader) = mysql_fetch_row($result);
/* CoRTable = Civilian or Ruler Table:       Civilians: user_weapons  Rulers: region_weapons
CoRIdName:   Civilian: user_id  Ruler: nation_id
CoRId;    The Id from the user or nation
YW:  YourWeapons
*/
if($leader = 'yes'){
$CoRTable = "region_weapons";
$CoRIdName = "region_id";
$CoRId = $nationid;
}else{
$CoRTable = "user_weapons";
$CoRIdName = "user_id";
$CoRId = $userid;
}
?>
<html>
<head>
<title>CriticalInvasion - Weapons</title>
<link href="./css/index.css" rel="stylesheet" type="text/css">
</head>
<body>
		<?php
		$query = "SELECT * FROM " . $CoRTable . " INNER JOIN weapons ON " . $CoRTable . ".weapon_id = weapons.weapon_id WHERE " . $CoRIdName . " = '$CoRId'";
		$result = mysql_query($query);
		$numrows = mysql_num_rows($result);
		if($numrows > 0){
			while($YW = mysql_fetch_array($result)){
				echo "<div id='attack_left'>" . $YW['weapon_name'] . "</div><div id='attack_right'>" . $YW['ammount'] . "</div>";
			}
		}elseif(($numrows <= 0) && ($leader = 'yes')){
			echo "<div id='text_text'>This nation doesn't have any weapons...</div>";
		}elseif(($numrows <= 0) && ($leader = 'no')){
			echo "<div id='text_text'>You don't have any weapons...</div>";
		}
		?>
</body>
</html>

 

edit.php

<?php
session_start();
require_once './config.php';
require_once './checkuserid.php';
$query = "SELECT leader FROM users WHERE user_id = '$userid'";
$result = mysql_query($query);
list($leader) = mysql_fetch_row($result);
?>
<html>
<head>
<title>CriticalInvasion - Edit</title>
<link href="./css/index.css" rel="stylesheet" type="text/css">
</head>
<body>
	<div id='text_text'>
		<? echo $userid . " " . $leader; ?>
	</div>
</body>
</html>

Link to comment
Share on other sites

You are assigning a value rather than comparing

elseif(($numrows <= 0) && ($leader = 'yes')){

elseif(($numrows <= 0) && ($leader == 'yes')){

Also why would the number of rows be less that 0. You cant return a negative number of records

elseif(!$numrows && $leader == 'yes'){

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.