-1

So below this is my JQUERY script which i use , i send the value from slider to and input and than i use to in PHP to GET request .

<script>

$(document).ready(function() {

  $("#slider1").slider({

      min: 0, //minimum value
      max: 1100, //maximum value
      animate: true,
value: 50, //default value
      slide: function(event, ui) {
          $("#value1").val(ui.value);
          }
      });

  $("#value1").val($("#slider1").slider("value"));
});

  </script>

I want some help in keeping the value on the slider after refresh here is my form and PHP

<form action='<?php echo htmlspecialchars("same_page.php") ?>' method='GET'><input id="value1" name='to' type="text" style='  border: 0px;' />
<div id="slider1"></div>
<input type='submit' class='btn btn-default'/>
</form>

<?php 
if(isset($_GET['to'])){
if($_SERVER['REQUEST_METHOD'] == 'GET'){
mysql_connect('localhost','root','GoogleFacebook') or die(mysql_error());
mysql_select_db('phones') or die(mysql_error());
$to = mysql_real_escape_string($_GET['to']);
if(!empty($to)){
$query = mysql_query("SELECT * FROM price WHERE phone_price BETWEEN 0 AND " .$to );
while($row = mysql_fetch_array($query)){
print '<p>';
print $row['phone_name'];
print '<b>';
print $row['phone_price'];
print '</b>';
print '</p>';
}
}
else{

  print"<script>alert('Price Range cannot be empty');</script>";
  print("<script>window.location.assign('slide.php');</script>");
}
}
}
?>

I dont know much jquery therefore i tried the slider from JQUERY original website , i am able to retrieve results from DATABASE but i don't know the way t keep the slider value the same , is there a way to get the slider value from the url like same_page.php/to?=500 i want the "500" .

PLEASE DONT TELL ME I USE OBSOLETE MYSQL which will be removed from PHP 7

Wasim Ahmad
  • 409
  • 3
  • 14
  • ok but its not , i am asking about JQUERY SLIDER and other things thats wrong, i just got the vote down privilege and now its gone :P – Wasim Ahmad May 02 '15 at 13:51
  • It answers your question, _“is there a way to get the slider value from the url like same_page.php/to?=500 i want the "500"”_ – CBroe May 02 '15 at 14:09

1 Answers1

0
  $("#slider1").slider({

      min: 0, //minimum value
      max: 1100, //maximum value
      animate: true,
      value: 50, // <<<< THAT LINE!!
      slide: function(event, ui) {
          $("#value1").val(ui.value);
          }
      });

  $("#value1").val($("#slider1").slider("value"));
});

Maybe you could echo out the value you've stored there by using PHP? Or maybe store the current value in a cookie and read it out inside the slider's initiation...


Answer:

var a = window.location.href ; var matches = a.match(/\d+$/); console.log(matches);
Rick Bakker
  • 76
  • 1
  • 7
  • you mean i should make sessions or use cookies , i think there maybe a better way than the two , if nothing works ill use cookies or sessions and i think echoing is a bad idea cause it will lead to 100 errors – Wasim Ahmad May 02 '15 at 13:31
  • Why would it lead to errors? When you are using a correct error handling it should not. – Rick Bakker May 02 '15 at 13:41
  • no bro i tried it as my PHP code only runs when $GET is set therefore the variable inside it is always undefined i will try $_GLOBALS[]; maybe it will help – Wasim Ahmad May 02 '15 at 13:43
  • Please post it as an answer. Not an comment. – Rick Bakker May 02 '15 at 13:47