views:

34

answers:

1

Currently I am using MySQLi to parse a CSV file into a Database, that step has been accomplished. However, My next step would be to make this Database searchable and automatically updated via jQuery.ajax().

Some people suggest that I print out the Database in another page and access it externally.

I'm quite new to jquery + ajax so if anyone could point me in the right direction that would be greatly appreciated.

I understand that the documentation on ajax should be enough to tell me what I'm looking for but it appears to talk only about retrieving data from an external file, what about from a mysql database?

The code so far stands:

<head>     
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt; 
</head> 
<body> 
<input type="text" id="search" name="search" /> 
<input type="submit" value="submit"> 
<?php 
    show_source(__FILE__); 
    error_reporting(E_ALL);ini_set('display_errors', '1'); 
    $category = NULL; 
    $mc = new Memcache; 
    $mc->addServer('localhost','11211'); 
    $sql = new mysqli('localhost', 'user', 'pword', 'db'); 

    $cache = $mc->get("updated_DB"); 

    $query = 'SELECT cat,name,web,kw FROM infoDB WHERE cat LIKE ? OR name LIKE ? OR web LIKE ? OR kw LIKE ?'; 

    $results = $sql->prepare($query); 
    $results->bind_param('ssss', $query, $query, $query, $query); 
    $results->execute(); 
    $results->store_result();    
?> 

</body> 
</html>
+2  A: 

I understand that the documentation on ajax should be enough to tell me what I'm looking for but it appears to talk only about retrieving data from an external file, what about from a mysql database?

Close. It fetches data from a URI. You need to provide a URI that the data can be requested from (so you need a server side script to get the data from the database and expose it over HTTP — you can't talk directly to the database from the browser).

You have got your data already, so you just need to write views for it.

Usually, people will write an HTML view first so they can build on something that works.

Then you just need to write an alternative view that generates data in a fashion that is easy to parse with JavaScript. JSON is popular, and PHP comes with facilities for generating JSON output.

jQuery will set an X-Requested-By header that you can use to choose between returning HTML or JSON output.

David Dorward