search

Home  >  Q&A  >  body text

Sum a specific range of numbers in a column using MYSQL

<p>I have a slider that calculates the BPM of a song. Range is 15 to 300 bpm. It connects to MySql database using php language and when I press edit button I can change its value. For example from 50 to 55bpm. table=users|columns=song_one. </p> <p><code><input value="<?php echo $this->data->song_one;?>" name="song_one" type="range" min="15" max ="300" value="100 "Read-only>\</code></p> <p>What I want is if I change the value below 15 and above 300, not accept it. How can I do this? I've heard something about constraints..</p> <p>I tried it, but it didn't work. </p> <pre class="brush:php;toolbar:false;">ALTER TABLE users ADD CONSTRAINT song_one CHECK (num >= 15 AND num <= 300);</pre> <p>Any information would be very helpful, thank you</p>
P粉821274260P粉821274260457 days ago642

reply all(1)I'll reply

  • P粉106711425

    P粉1067114252023-09-05 13:15:07

    This will work for you.

    ALTER TABLE users
        MODIFY COLUMN song_one INT CHECK (song_one >= 15 AND song_one <= 300);

    reply
    0
  • Cancelreply