tags:

views:

152

answers:

3
<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?

+3  A: 

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.

Gumbo
A: 
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 '<=')

rascher
+1  A: 

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.

Ali
I was going to suggest the same... I don't see why some despise it. You could tighten it up even further by reducing it to:<pre><code><a href="post.php?id=4 ?>">Expand</a></code></pre>
Hans