1

The overall goal is to relay information from a mysql server via a php file to the webpage being viewed. More specifically I want to target certain aspects of the php file, or certain tables in the database, and display them in different divs on the webpage. Given my limited experience I'm not sure how best to do this but I would imagine the flow would be something like this...

(I apologize for the limited code detail but everything I tried didn't seem like the right approach so I'll keep it broad so it can be open to suggestions.)

Call php file and request certain variables such as:

 $(document).ready(function(){
    //call sqlrelay.php
    //ask for some variable ($row) or some section of the code (within the if statement)
    //display it in div ('#collapseOne')
};

Listen with the php file (sqlrelay.php) such as:

<?php
    //if request received from client side do this:
    include ("connection.php");
    $sendtable = "SELECT timein FROM timestamp1 ORDER BY id DESC LIMIT 1"; 
    $result=mysqli_query($link, $sendtable);
    $row = mysqli_fetch_array($result);
    $table = $row['timein'];
    echo $table;
<?
kybak
  • 820
  • 3
  • 13
  • 28

1 Answers1

0

Look the API: http://api.jquery.com/jquery.ajax/

or use my code.

$(document).ready(function() {
   $.ajax({
       method: "POST",
       url: "sqlrelay.php",
       data: {
         row: "your query"   
       },
       success: function(data) {
           $('#collapseOne').html(data);    
       }
   }); 
});

and your PHP looks like this to catch the row request

<?php

$row = $_POST['row'];

echo $row;
mapodev
  • 988
  • 8
  • 14
  • So, if I understand correctly, everything within the data brackets is what is being requested, correct? I'm still a little confused about what the 'row: "your query'" part means. And what would the php file look like? – kybak Nov 27 '15 at 20:42
  • Is the php you have written missing something? Because I thought I needed to put my mysqli query there. Do I put it where "your query" is in the ajax call? I don't see the benefit in doing that. – kybak Nov 27 '15 at 21:11