Hi,
I've these values:
a) < 100 000 = 5 points
b) 100 000 - 250 000 = 4 points
c) > 250 000 = 3 points

$a = 140000;
$b = 23;

if ($a > 250000)
{
  $b = 3;
  echo $b;
}

if ( 100000 < $a <= 250000)
 {
   $b = 4;
   echo $b;
 }
 
if ($a < 100000)
 {
   $b = 5;
   echo $b;
 }

the logic wrong here??????????????
if i put echo $b outside of the if at the end of all the above if, does it store the value to $b.

How to sort integer value from database,
example column values from maximum to minimum and the other way around?
I know how to find max or min value. and how to nicely put it in table so that it looks this way:

Item id item title item values
this will get value from db, from this will get value from db, from i'm not sure how to
query row + next row query row + next row do this part????

<table>
<tr>
for ( )
{
<td>Item id</td>
<td>item title</td>
<td>iteam value????</td>
}
</tr>
<table>

for (int i=0; i<10; i++)
{

   if (number[i] > max) {
      max=number[i];
      }
   if (number[i] < min) {
      min=number[i];
      }

Dani AI

Generated

: the immediate bug is the chained comparison. PHP does not support expressions like 100000 < $a <= 250000 the way some languages do. Use explicit Boolean logic or an if/elseif/else chain so only one branch runs and boundaries are clear. A small, safe helper keeps the logic readable and avoids leaving $b uninitialized:

function pointsFromValue($value) {
    $v = (int)$value;
    if ($v < 100000) {
        return 5;
    } elseif ($v <= 250000) {
        return 4;
    } else {
        return 3;
    }
}

$b = pointsFromValue($a);
echo $b;

For sorting rows, is right: do the ordering in the database when possible. Let the DB return rows in the order you need and, if useful, compute the points there too with a CASE expression so PHP just prints results. Example SQL + fetch pattern (using PDO):

$sql = "
SELECT id, title, value,
  CASE WHEN value < 100000 THEN 5 WHEN value <= 250000 THEN 4 ELSE 3 END AS points
FROM items
ORDER BY value DESC
";
$stmt = $pdo->query($sql);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

If you must sort in PHP (custom comparator, computed keys, or small result sets), use usort or array_multisort. See PHP usort function and PDOStatement::fetchAll for reference. Final cautions: choose inclusive/exclusive bounds consistently, cast values to int before comparing, escape output with htmlspecialchars() when printing into a table, and prefer ORDER BY with an index for large datasets to avoid pulling everything into PHP.

Why not use order by clause in your query itself ?

$query = "select * from table order by colname [asc | desc ]";

[asc | desc ] is optional. You can sort the records in ascending order or descending order on one or multiple columns.
Or, you can also fetch the records from the table into an array and sort the array and get the max or min value from it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.