javascript - Get exact mysql cell content using js / jquery / ajax -


i wish ask clues in function construction of web page. target read 1 cell mysql table, put in 1 cell of web page table. next, cell must self-refreshing each x seconds. whole web page table have 25 refreshing columns in 25 rows beginning. mysql table has 26 columns, 25 contains needed , editable data.

a bit of coding:

main site: web page cell, contain refreshing content (now includes non-working , prototype coding)

<td>map_loader2(1,2) &nbsp;<div id="whateva"></div></td>     

php request in separate .php file calling function (only here i'm sure written , working):

<?php $servername = "localhost"; $username = "root"; $password = "admin"; $dbname = "map"; $loader="select c$column map_1 map_1.rownumber = $row ";  // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }   $result=$conn->query($loader); $array = mysql_fetch_row($result); echo json_encode($array); if ($conn->query($loader) === true) {    // echo "updated successfully";    header("location: http://sectortrader/main_site_editor.php"); /* redirect browser */  } else {     echo "error updating record: " . $conn->error; }  $conn->close(); ?> 

lastly - i've managed create after many failed attempts , dozens of different tutorials countless pages of documentation @ w3 few other sources:

<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script language="javascript" type="text/javascript"> setinterval(function map_loader2(column, row)     {     $("#whateva").load("map_loader_query.php");     },5000); //refreshing interval </script> 

as refreshes after 5 seconds intended (however displaying errors - because doesn't proper values query), cannot figure out how force take arguments function. i'm quite greeny in php , mysql, , complete newbie in js/jquery/ajax. however, mini-game i'm trying write attempted improve weaky skill.

thanks spared time.

ps. i've totally forgot share function i've tryied earlier:

<?php  function map_loader($column, $row)     {     $servername = "localhost";     $username = "root";     $password = "admin";     $dbname = "map";     // create connection     $conn = new mysqli($servername, $username, $password, $dbname);     // check connection     if ($conn->connect_error)          {         die("connection failed: " . $conn->connect_error);         }     $loader="select c$column map_1 map_1.rownumber = $row ";     $result=$conn->query($loader);     $conn->close();     return $result;      } ?> 

with wished use follows:

<tr>         <td rowspan="25">&nbsp;</td>         <td>1</td>         <td>window.map_loader2(1,1) &nbsp;</td>         <td>map_loader2(1,2) &nbsp;<div id="whateva"></div></td>         <td>&nbsp;</td> . . . <tr>         <td>2</td>         <td><?php  map_loader(2,1); ?>&nbsp;</td>         <td><?php  map_loader(2,2); ?>&nbsp;</td>         <td>&nbsp;</td> . . . 

and on, , again, , again once more... of course, done somehow better - firstly wish make working, secondly can improved. unfortunately, wont work easly want.

first of must use ajax want accomplish. need create set interval function executed every 5 seconds , inside ajax call map_loader_query.php page , success function return data. if data queried db html, need insert data queried inside div whateva or td.

<td><div id="whateva"></div></td>      <script>     setinterval(function()     {          $.ajax({           type:"post",           url:"map_loader_query.php",           success:function(data) {               $('div#whateva').html(data);           }         });     }, 5000); </script> 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -