<a href="post.php?id=4&rows=<?php if ($_GET['rows']) echo $_GET['rows'] + 10; else echo "10"; ?>">Expand</a>
Can I get this to only return true if the numbers are between 10 and 200?
<a href="post.php?id=4&rows=<?php if ($_GET['rows']) echo $_GET['rows'] + 10; else echo "10"; ?>">Expand</a>
Can I get this to only return true if the numbers are between 10 and 200?
Use this condition expression:
if ($_GET['rows'] > 10 && $_GET['rows'] < 200)
It only evaluates to true if the value of $_GET['rows']
is greater than 10 and smaller than 200. For inclusion of 10 and 200 use >=
(greater or equal) and <=
(smaller or equal) instead.
if (($_GET['rows'] >= 10) && ($_GET['rows'] <= 200)) echo $_GET['rows'] + 10; else echo "10";
(assuming you want "10" and "200" to return true, otherwise just use '<' and '>' rather than '<=')
If you're so inclined you might want to use the ternary operator here, i.e.
<a href="post.php?id=4&rows=<?php echo ($_GET['rows'] > 10 && $_GET['rows'] < 200) ? $_GET['rows'] + 10 : '10' ?>">Expand</a>
Some people despise it, I think it neatens things up in situations like this.