# Variable not changing when it should - from NULL

## Recommended Posts

```if (\$rowcats->followersrange == "2000-5000")
{
\$lowrange2000 = "2000";
\$lowestrange = \$lowrange2000;
\$numberpeople = \$rowcats->numberpeople;
}
if (\$rowcats->followersrange == "5000-10000")
{
\$lowrange5000 = "5000";
if (\$lowrange5000 < \$lowestrange) {
\$lowestrange = \$lowrange5000;
\$numberpeople = \$rowcats->numberpeople;}
}

if (\$rowcats->followersrange == "10000-15000")
{
\$lowrange10000 = "10000";
if (\$lowrange10000 < \$lowestrange) {
\$lowestrange = "\$lowrange10000";
\$numberpeople = \$rowcats->numberpeople;}
if (\$lowestrange == NULL) { echo "yes";}
echo "\$lowestrange";
}
if (\$rowcats->followersrange == "15000-20000")
{
\$lowrange15000 = "15000";
if (\$lowrange15000 < \$lowestrange) { \$lowestrange = \$lowrange15000;\$numberpeople = \$rowcats->numberpeople;}
}```

We are trying to find the lowest range from the entries added to a database, so at the end, we can say the range is FROM... TO...

They might opt for 2-5k, or 5-10k etc.

If they opt for 10-15k, then the lowest range is 10,000.

We have a result of 10000 - 15000.  So the \$lowrange10000 = "10000".

Therefore, this should be echoing the \$lowestrange from 7th line up in this code, but it remains at NULL, based on:

\$lowestrange = NULL;, set at the top of the code.

Why is that?

##### Share on other sites

I have just set this at the top:

\$lowestrange = 50000;
\$highestrange = 500;

It works, but is it the right thing to do.  As 10000 is NOT lower than NULL...?!

##### Share on other sites
28 minutes ago, simona6 said:

if (\$rowcats->followersrange == "2000-5000")

How is \$rowcats->followersrange being set?

Edited by mconte
need to be specific
##### Share on other sites

At the top, as

`\$followersrange = NULL;`

##### Share on other sites
33 minutes ago, simona6 said:

if (\$rowcats->followersrange == "10000-15000")

it'll only echo \$lowestrange if this expression is evaluated as true... wait, can you show your code with your changes?

Edited by mconte
##### Share on other sites
```\$lowestrange = 50000;
\$highestrange = 500;

if (\$rowcats->followersrange == "2000-5000")
{
\$lowrange2000 = "2000";
\$lowestrange = \$lowrange2000;
\$numberpeople = \$rowcats->numberpeople;
}
if (\$rowcats->followersrange == "5000-10000")
{
\$lowrange5000 = "5000";
if (\$lowrange5000 < \$lowestrange) {
\$lowestrange = \$lowrange5000;
\$numberpeople = \$rowcats->numberpeople;}
}

if (\$rowcats->followersrange == "10000-15000")
{
\$lowrange10000 = "10000";
if (\$lowrange10000 < \$lowestrange) {
\$lowestrange = "\$lowrange10000";
\$numberpeople = \$rowcats->numberpeople;}
}
if (\$rowcats->followersrange == "15000-20000")
{
\$lowrange15000 = "15000";
if (\$lowrange15000 < \$lowestrange) { \$lowestrange = \$lowrange15000;\$numberpeople = \$rowcats->numberpeople;}
}
if (\$rowcats->followersrange == "15000-20000")
{
\$lowrange15000 = "15000";
if (\$lowrange15000 < \$lowestrange) { \$lowestrange = \$lowrange15000; \$numberpeople = \$rowcats->numberpeople;}
}    ```

Though it was set to \$lowestrange = NULL; before, at the top.

##### Share on other sites

if all you are doing is mapping input values to output values, don't write out conditional logic for every possible choice. if the input to output mapping doesn't contain any calculable relationship, define a data structure (array, database table) to map the input to the output. for the example values you have shown, wouldn't you just break apart the value at the '-' character and use the first part as the lowest range value?

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• #### Activity

• Chat
×
• Create New...