1

A very good morning, i am currently working on a simple php project, the goal of the application is to read Oracle data and display the result, i've completed this part. I am having a little doubt on how to pass querystring along with JQuery, please advice. Many thanks in advance.

index.php - this is where i am passing the querystring index.php?campus=abc&floor=xyz

<html>
<head>`enter code here`
    <title>Olympia College :: Kiosk</title>
    <link rel="Stylesheet" type="text/css" href="assets/css/kiosk.css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
// $(document).ready(function()
// {
//   $("#responsecontainer").load("contents.php");
//   var refreshId = setInterval(function()
//   {
//       $("#responsecontainer").load('contents.php?randval='+ Math.random());
//   }, 1000);
//   $.ajaxSetup({ cache: false });
// });

function update() {
  $("#notice_div").html('<img src="indicator.gif" alt="Synchronizing data, please wait a moment.."/>&nbsp;&nbsp;Synchronizing data, please wait a moment..');
  $.ajax({
    type: 'POST',
//    data: '{campus, floor}',
    url: 'timetable.php',
    timeout: 5000,

        success: function(data) {
          $("#some_div").html(data);
          $("#notice_div").html('');
          window.setTimeout(update, 10000);
        },

        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $("#notice_div").html('Timeout contacting server..');
          window.setTimeout(update, 60000);
        }
    });
}
$(document).ready(function() {
    update();
});

</script>
</head>
<body>
    <!--<div id="responsecontainer">
    <?php //echo date("l, F d, Y h:i:s" ,time());?>
    </div>-->
    <div id="main">
        <div id="left"><img src="assets/images/oc_logo.png" alt="Olympia College Malaysia"></img></div>
        <div id="right"><div id="notice_div"></div><div id="fright"><a href="setting.php" title="Change settings">Setting</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="bug.php" title="Send bug report">Bug Report</a></div></div>    
    </div>
    <div id="line"></div>

    <br />
    <div id="some_div"></div>
</body>

timetable.php

<?php
$datasource = "******";
$hostname = "******";
$username = "*****";
$password = "*****";
$database = "*****";
$campus = $_REQUEST['campus'];
$floor = $_REQUEST['floor'];

//KL CAMPUS
if ($campus == 'ockl')
    $campus = 'KL CAMPUS';
elseif ($campus == 'ocpj')
    $campus = 'PJ CAMPUS';
elseif ($campus == 'ocpg')
    $campus = 'PENANG CAMPUS';
elseif ($campus == 'ocip')
    $campus = 'IPOH CAMPUS';
elseif ($campus == 'ockt')
    $campus = 'KUANTAN CAMPUS';
elseif ($campus == 'ocjb')
    $campus = 'JB CAMPUS';

//echo $_REQUEST['campus'];

$connect = odbc_connect($datasource, $username, $password);

    if(!$connect){
        echo "Unable to connect!<br /><br />";
    }
    else {
        //echo "Successfully connected!<br /><br />";
    };

$query = "SELECT DISTINCT 
          RESOURCE_DAY_TIME_SETUP.DAY, 
          RESOURCE_DAY_TIME_SETUP.FLOOR_CODE,
          RESOURCE_DAY_TIME_SETUP.RESOURCES_CODE,
          RESOURCE_DAY_TIME_SETUP.CAMPUS 
          FROM RESOURCE_DAY_TIME_SETUP WHERE CAMPUS LIKE '" . $campus . "'";
$result = odbc_exec($connect, $query);

echo "<table border='1'>";
echo "<tr> <th>Day</th> <th>Floor</th> <th>Room</th> <th>Duration</th> <th>Start</th> <th>End</th> <th>Lecturer</th> <th>Status</th> <th>Campus</th> </tr>";

while (odbc_fetch_row($result)){
    $day = odbc_result($result,1);
        $floor_code = odbc_result($result, 2);
    $resources_code = odbc_result($result,3);      
    $campus = odbc_result($result,4);
        echo "<tr>";
        echo "<td>$day</td>";
        echo "<td>$floor_code</td>";
        echo "<td>$resources_code</td>";
        echo "<td>$resources_code</td>";
        echo "<td>$resources_code</td>";
        echo "<td>$resources_code</td>";
        echo "<td>$resources_code</td>";
        echo "<td>$resources_code</td>";
        echo "<td>$campus</td>";
        echo "</tr>";
}

odbc_close($connect);

echo "</table>";
?>

Hope someone here can shed some light to point me in the correct direction, many thanks in advance.

1 Answer 1

1

Since you're not posting any data other than your query string I think you want to be using GET instead of POST, but since your php file uses $_REQUEST both will work. Just format your data like this:

type: 'GET',
data: {campus: 'abc', floor: 'xyz'},
url: 'timetable.php',
Sign up to request clarification or add additional context in comments.

3 Comments

+1 - Also, the OP might want to set cache to false if he's using a GET, since many browsers notoriously cache the results.
Hi Paul, thanks for the reply. I need to pass the data as querystring, i.e. index.php?campus=ockl&floor=1. Reason is that this simple app has to display the details of the on going classes by floor and i prefer not allow users to set the values for the querystring parameters, i am thinking of launching the index.php page with the preset querystring values from the address bar itself.
@Sashi jQuery will do that for you if you change the type to 'GET'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.