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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • 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.