Jump to content

[SOLVED] question regarding BETWEEN Syntax


abdfahim

Recommended Posts

I guess you could put an if() statement before that, to check which is greater.

 

<?php
$a = 400;
$b = 300

if($a>$b) {

// Swap the values of $a and $b
$temp = $b;
$b=$a; // Is now 400
$a=$temp; // Is now 300

}

$query = "SELECT * FROM `table1` WHERE `col1` BETWEEN ".$a." and ".$b;
?>

 

Haven't used BETWEEN before so not sure if that would work :D  But I'd say give it a go, makes sense to me!

no, both a and b is the input given by the user in two text boxes. I distinguish the two text boxes as higher and lower, but if some one just give inverse entry, then it will show error.

You could get mysql to determine this for you, but that's much more work when any type of validation would prevent this issue on the server side.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.