I have a varible that is set at as a different value for each page this is called $mode.

Currently I have succesfully set up a drop down menu that can filter the table and refresh the results based on that filter chosen, yet I need to call this $mode variable into the query to be able to get the true results back that I require.

The php page to call the filter code is as follows

$q = intval($_GET['q']);

$con = mysqli_connect('x','x','x');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));

$sql="SELECT * FROM tab1 WHERE info = '".$q."' and id='$mode' LIMIT 10";
$result = mysqli_query($con,$sql);

echo "blar blar blar

and another one that shows the results on the page

function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;

<select name="Info" onchange="showUser(this.value)">
  <option value="">Select a mod:</option>
  <option value="1">this</option>
  <option value="2">that</option>
  <option value="3">other</option>
<div id="txtHint"><b>NEw info shows here</b></div>

IN the page that these pages that I echo the above page into, it has the variable $mode
, which sucessfully is iised in other queries in the page but $q is passed from the drop down fine but id='$mode' is showing as blank

How do I get this $mode to show the true value in this instance please?

Thanks for your help

2 Years
Discussion Span
Last Post by mpc123


In info.php you are having 2 variable such as $q and $mode.

but you are getting a value for $q variable from dropdown value.

what abt $mode?


Anybody give me any idea at least?

I have tried in xmlhttp.open setting &$mode= but I can't get it to work


The php script runs "as is", prompted by the Ajax call. So, $mode needs to be set somewhere in order for the query to run successfully. You could pass it via Ajax:


And pick it up in the php thus...

$mode = $_GET['mode'];

BUT - you are using mysqli, so be kind to yourself and use parameter binding and prepared statements. Otherwise you will set yourself up for SQL injection - and yes - it's even more painful than it sounds.

Edited by diafol


WOW thanks for the advice, I will change i and also try what you have sent me, thanks again


BTW that works great thank you very much !!

Votes + Comments
Thanks for coming back and letting us know
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.