arrays - comparison operation in if statment php

704

ok i have a lvlcheck.php that compares the players experience and outputs the correct lvl based on experience. yet i cany get it to work. nothing shows up when i echo $lvl. its like all the the statements in lvlcheck.php are failing. below is my code.

this is my array to draw user stat experience

$sql = 'SELECT a.user, a.' . $stat1 .', b.' . $stat2 .'
    FROM curstats a, experience b
    WHERE a.user = b.user order by ' . $stat2 .' desc LIMIT 15';
$result = mysql_query($sql) or die(mysql_error());
 array();
$rank = 1;
while($row = mysql_fetch_assoc($result)) {

   ?>

<tr>
<td align="center"><font color="#d3d3d3"><?php echo $rank++; ?></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['user'];?></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row[$stat2]; ?></font></td>
<td align="center"><font color="#d3d3d3"><?php
  $stat3 = $row['stat2'];   
require 'includes/lvlcheck.php'; 
echo $lvl;  
?></font></td></tr>

 <?php
}  
 ?>

and here is my lvl check. code.

<?php 
if($stat3 > 0 && $stat3 < 83) {
$lvl = "1";
}
if($stat3 > 83 && $stat3 < 174) {
$lvl = "2";
}
if($stat3 > 174 && $stat3 < 276) {
$lvl = "3";
}
if($stat3 > 276 && $stat3 < 388) {
$lvl = "4";
}
if($stat3 > 388 && $stat3 < 512) {
$lvl = "5";
}

i know its the variables $stat1 and $stat2 are being assigned correctly because it will display the right experience just wont convert the the experience into a lvl to output $lvl any idea?

784

Answer

Solution:

< 83 means less than 83, so the highest valid value would be 82

> 83 means greater than 83, so the lowest valid value would be 84

If you checking for 83, you won't get results.

<= 83 means less than or equal, so 83 would be included. For example...

684

Answer

Solution:

I had to remove the quotation marks surrounding$stat2 in$stat3= $row['$stat2'];

Now, it reads$stat3 = $row[$stat2];.

People are also looking for solutions to the problem: oop - PHP get_called_class() as variable for referencing static property

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.